Page 1 of 1

[SOLVED] Finding record number of newly inserted record

Posted: Fri Jun 10, 2005 2:45 am
by davidtee1
I use an auto increment field to uniquely identify my records in a MySQL table.

When I insert a new record, a new unique id is created but how can I find out what the number is so I can refer to it immediately?

Any help gratefully received.

Posted: Fri Jun 10, 2005 3:33 am
by phpScott
refer to http://www.php.net/manual/en/function.m ... ert-id.php

to get the last inserted id

Posted: Fri Jun 10, 2005 3:36 am
by malcolmboston

Code: Select all

// insert statement + call here
$lastID = mysql_insert_id();
this is incredibly useful on auto-incrementing ID rows

Posted: Fri Jun 10, 2005 3:42 am
by davidtee1
Thanks guys. Brilliant. I knew it would be in there somewhere!

David