I have 2 separate forms. The first form handler determines if the second form is needed. Each form populates a separate database table. I need to be able to link corresponding rows later. I am trying to do so by calling SCOPE_IDENTITY() after the first form and setting it to a variable to be used as the id in the second form.
I hope that made sense. Here’s my code:
$iquery = mysql_query("INSERT INTO pending (date, ip) VALUES('".$_POST['date']."', '".$_POST['ip']."')");
$asdf = SCOPE_IDENTITY();
echo $asdf;
Which give gives me this:
Fatal error: Call to undefined function scope_identity() in
/public_html/test/index.php on line 138
What is the correct way to do this? keep in mind I need the result to be set as a variable.
Use
mysql_insert_id():or in PDO (which I’m advising you to move, here is a nice tutorial):