natefanaro
Technical User
I have seen the LAST_INSERT_ID() function but for some reason it either will not work for what I am looking to do, or I was using it wrong. I am trying to get the last number that is given by the auto_increment number in mysql. But when I look for info on LAST_INSERT_ID(), it's always used in another sql query. I am trying to do something similiar to this: $lastid = LAST_INSERT_ID()
Here's an example of my current code:
$db = mysql_connect("localhost", "quizcrea_root"
mysql_select_db("quizcrea_quiz",$db);
$sql = "INSERT INTO results (email,name,num1,num2,num3,bcolor,tcolor) VALUES ('$email','$name','$num1','$num2','$num3','$bcolor','$tcolor')";
$result = mysql_query($sql);
// I tried adding this but it gives an error
$lastid = LAST_INSERT_ID()
//end code
any suggestions?
Here's an example of my current code:
$db = mysql_connect("localhost", "quizcrea_root"
mysql_select_db("quizcrea_quiz",$db);
$sql = "INSERT INTO results (email,name,num1,num2,num3,bcolor,tcolor) VALUES ('$email','$name','$num1','$num2','$num3','$bcolor','$tcolor')";
$result = mysql_query($sql);
// I tried adding this but it gives an error
$lastid = LAST_INSERT_ID()
//end code
any suggestions?