View Full Version : How to get back the primary key of a new entry?

01-15-2010, 03:05 AM
In my SQL table, I have a primary key set up to auto-increment, called UserID. I add a row to the table by using the following code:

$sql = "INSERT INTO LUM_User (FirstName, LastName, VerificationKey, Email, Gender, DateJoined, IpJoined) VALUES ('$FirstName','$LastName','$VerificationKey','$Email','$Gender','$DateJoined','$IpJoined')";

if(!mysql_query($sql,$con)) {
die('Fatal Error: ' . mysql_error());

How can I get back the value of the primary key of this new entry? This is probably a simple question but I am a novice PHP/SQL programmer. Thanks.

01-15-2010, 03:08 AM
mysql_insert_id() (http://www.php.net/mysql_insert_id)