missanna08 Posted June 4, 2014 Share Posted June 4, 2014 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()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/288978-session-id-from-another-table-to-be-entered-in-another-table/ Share on other sites More sharing options...
cyberRobot Posted June 4, 2014 Share Posted June 4, 2014 Have you checked to see if the ID variable contains a value? For example, you could try something like this: $empid = $_SESSION['empid']; var_dump($empid); Also, do you have PHP errors enabled? The following lines can be added to the top of your script to show all errors and warnings: <?php //REPORT ALL PHP ERRORS error_reporting(E_ALL); ini_set('display_errors', 1); ?> Of course, the above code should be removed once the issue is fixed. Quote Link to comment https://forums.phpfreaks.com/topic/288978-session-id-from-another-table-to-be-entered-in-another-table/#findComment-1481839 Share on other sites More sharing options...
missanna08 Posted June 4, 2014 Author Share Posted June 4, 2014 Thanks for the reply! It says that the empid is "null". HOw do i fix this issue? my session not storing the empid? Quote Link to comment https://forums.phpfreaks.com/topic/288978-session-id-from-another-table-to-be-entered-in-another-table/#findComment-1481843 Share on other sites More sharing options...
cyberRobot Posted June 4, 2014 Share Posted June 4, 2014 Perhaps it's named something else. You could try echoing the SESSION variable to see what it contains: session_start(); echo '<pre>' . print_r($_SESSION, true) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/288978-session-id-from-another-table-to-be-entered-in-another-table/#findComment-1481844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.