Jump to content

Session id from another table to be entered in another table


missanna08

Recommended Posts

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')";













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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.