I'm currently doing a computing project which requires me to use an id(which is a primary key in one table) as a secondary key for another table. I want to use sessions to keep track of the variable using commands like this
$id=$_SESSION['id'];
However I'm currently having the problem of getting id from the table it's the primary key in. This is the mysql statement I'm using.
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);}
$sql='INSERT INTO user(email,pass) VALUES ("'.$email.'","'.$pass.'")';
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql='SELECT id FROM user WHERE user(email)="'.$email'"'
I've done a bit of looking but haven't found any examples of how to do this. The information is being sent to the database and id's are being generated and I will add validation once it all works. However I can't retrieve the specific id's from the database. Also is there a specific variable I have to use (like $result) or do I just do $id=$sql after the query is completed?