I want to store LAST_INSERT_ID()
aka Case_ID
and call it in another html page. How do I do this?
$query.= "insert into Picture (Case_Pic,Case_ID)
values ('" .addslashes($imagefile). "', LAST_INSERT_ID())" ;
I want to store LAST_INSERT_ID()
aka Case_ID
and call it in another html page. How do I do this?
$query.= "insert into Picture (Case_Pic,Case_ID)
values ('" .addslashes($imagefile). "', LAST_INSERT_ID())" ;
Save it in session. Like you have id as follows:
$id = '112';
session_start();
$_SESSION['case_id'] = $id;
and then in other html page:
<?php
session_start();
//Now you can use $_SESSION['case_id'] however you want here.
?>
I hope it helps
EDIT: Just realised that you might also need a way to get the last insert ID.
As I can see from your code, you seem to be running 2 queries and are using the last insert ID of the previous query into the next query, if I'm not mistaken.
If that's the case, you will need to separate out the queries and at the end of your case table insert query use mysqli_insert_id if you are using MySQLi (which you should).
Example code:
$query = "INSERT INTO `Case` (`Case_name`) VALUES ('".mysqli_real_escape_string($db,$case_name)."')";
$q_obj = mysqli_query($db, $query);
$case_id = mysqli_insert_id($db);
$query2 = "INSERT INTO `Picture` (`Case_Pic`,`Case_ID`) VALUES ('".mysqli_real_escape_string($db, $imagefile)."', '".mysqli_real_escape_string($db, $case_id)."')";
And then, you will need to pass it to the HTML page via query string parameter:
header('Location:success.html?case_id='.$case_id);
And in your HTML page, use JavaScript to get the query string parameters, parse them and extract the case_id query string parameter