An application I’m working on requires that I store certain values in a database (coming from a submitted form). Like for example:
$sql="INSERT INTO Employment (JobTitle, StartDate, EndDate) VALUES('$_POST[jobtitle]','$_POST[startdate]','$_POST[enddate]')";
Once they’re in the database, how do I access them individually in the following context:
if ($jobtitle=='123') {
echo "You're a software developer.";
} elseif ($jobtitle=='1234') {
echo "You're a software tester.";
}
Essentially, it’s a recommender system where I need to be able to issue recommendations based off of the data in the database. I.e., if job title is this, if start date – end date = this, etc. I’m a beginner with mySQL. Any help would be greatly appreciated.
1) First, you need to know at least a little PHP. It sounds like you’ve gotten that far, and that you can successfully establish a connection to the database (at least to do your “insert”). Good.
2) Next, you need to know at least a little SQL. It sounds like that’s where you’re stumped at the moment. The most basic SQL commands are:
Select (usually people learn this one first ;))
Insert
Update
Delete
W3Schools has a series of great on-line tutorials that cover 1) and 2):
http://www.w3schools.com/php/php_mysql_intro.asp
3) Before you put anything into production, you should ALSO learn a bit about security:
Securing your web server (e.g. Apache)
http://bignosebird.com/security.shtml
Securing your database (e.g. mySQL)
http://www.symantec.com/connect/articles/securing-mysql-step-step
Securing your application (e.g. against cross-site scripting and SQL injection)
http://www.insanevisions.com/article/221/Tutorials/PHP-Security/