kwdelre Posted January 12, 2011 Share Posted January 12, 2011 If I am using this: mysql_query("INSERT INTO M1QuizResults (Email, Q1Choice, Q2Choice, Q3Choice, Score, Pass, Date_Taken, Time_Taken) VALUES(' " . $_SESSION['Email'] . " ', '$QChoice_1', '$QChoice_2', '$QChoice_3', '$Score', '$Pass', CURDATE(), NOW())") or die(mysql_error()); What would I use to find out what the row's "Id" is? "Id" is my primary key. I want to store this "Id" as a session variable. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/224146-getting-primary-key-from-new-row/ Share on other sites More sharing options...
Rifts Posted January 12, 2011 Share Posted January 12, 2011 cant you just do mysql_query("select id from m1quizresults where email = session['email'] ") obviously fix syntax Quote Link to comment https://forums.phpfreaks.com/topic/224146-getting-primary-key-from-new-row/#findComment-1158221 Share on other sites More sharing options...
inversesoft123 Posted January 12, 2011 Share Posted January 12, 2011 $currdate = CURDATE(); $now = NOW(); mysql_query("INSERT INTO M1QuizResults (Email, Q1Choice, Q2Choice, Q3Choice, Score, Pass, Date_Taken, Time_Taken) VALUES(' " . $_SESSION['Email'] . " ', '$QChoice_1', '$QChoice_2', '$QChoice_3', '$Score', '$Pass', $currdate, $now)") or die(mysql_error()); $selectlastid=mysql_fetch_array(mysql_query("SELECT id from M1QuizResults WHERE Date_Taken = '$currdate' AND Time_Taken='$now'")); echo $selectlastid[0]; Quote Link to comment https://forums.phpfreaks.com/topic/224146-getting-primary-key-from-new-row/#findComment-1158224 Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2011 Share Posted January 12, 2011 No extra query is needed - mysql_insert_id Quote Link to comment https://forums.phpfreaks.com/topic/224146-getting-primary-key-from-new-row/#findComment-1158230 Share on other sites More sharing options...
kwdelre Posted January 12, 2011 Author Share Posted January 12, 2011 No extra query is needed - mysql_insert_id Wow that was easy...thank you so much for your help everyone. Quote Link to comment https://forums.phpfreaks.com/topic/224146-getting-primary-key-from-new-row/#findComment-1158233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.