How to find id of last inserted row in MYSQL using PHP


To find id (auto increment) value of last inserted row, put the following code into the PHP page.


$link = mysql_connect('localhost', 'mysql_usenamer', 'mysql_password');
if (!$link) {
    die('Could not connect:to the database ' . mysql_error());
mysql_query("INSERT INTO mytable (user) values ('jijo')");
printf("Last inserted record has id %d\n", mysql_insert_id());

You can leave a response, or trackback from your own site.

Leave a Reply