Dùng hàm mysql_insert_id() để get id vừa được tạo.
<?php $con = mysql_connect("localhost", "peter", "abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("test_db",$con); $sql = "INSERT INTO person VALUES ('Børge','Refsnes','Sandnes','17')"; $result = mysql_query($sql,$con); echo "ID of last inserted record is: " . mysql_insert_id(); mysql_close($con); ?>