mysql_insert_id()
int mysql_insert_id([connection])This function returns the identification number of the
primary key of the last record inserted using
INSERT for the current connection, provided the
column utilizes AUTO_INCREMENT
and the value was not manually set. Otherwise, it returns 0. Here is
an example:
...
$sql_stmnt = "INSERT INTO workreq
(date, clientid, description)
VALUES(NOW( ), '1000', 'Network Problem')";
mysql_query($sql_stmnt);
$wrid = mysql_insert_id( );
print "Work Request ID: $wrid \n";
...Here is the output of this script:
Work Request ID: 5755