Search the Community
Showing results for tags 'insertquery'.
-
Hi I have two tables Employer and Job. Emp_ID as PK of Employer and Job_id as PK of Job. I want to put Emp_ID as Foreign key for jobs. and when the employer logs in his empid is being stored as a session and when he creates a job his empid will be entered in the job table. I've created my session, and insert query but it doesn't seem to work, as emp_id in Job table doesnt get updated. All my other values(cname, location) works. The empid is autoincrement from the Employer table. //joblisting.php code <?php session_start(); $empid = $_SESSION['empid']; if(!(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == "YES")) { header("Location: index.php"); exit; } $dbhost = 'localhost'; $dbname = 'jobseeker1'; $dbuser = 'root'; $dbpass = ''; $con = @mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname, $con); $cname=mysql_real_escape_string($cname); $jobtitle=mysql_real_escape_string($jobtitle); $jobtype=mysql_real_escape_string($jobtype); $jobresp=mysql_real_escape_string($jobresp); $jobreq=mysql_real_escape_string($jobreq); $location=mysql_real_escape_string($location); $salary=mysql_real_escape_string($salary); $phone=mysql_real_escape_string($phone); $email=mysql_real_escape_string($email); $sql="INSERT INTO `joblisting` (cname, jobtitle, jobtype, jobresp, jobreq, location, salary, phone, email, empid) VALUES('$_POST[cname]','$_POST[jobtitle]','$_POST[jobtype]','$_POST[jobresp]','$_POST[jobreq]','$_POST[location]','$_POST[salary]','$_POST[phone]','$_POST','$empid')"; $result=mysql_query($sql); if($result){ echo "1 job listing added"; echo "<a href='employerpage.php'> Go back to employer page</a>"; } else { echo "<a href='addjob.php'> Can not add job. Try again.</a>."; die(mysql_error()); } ?>