Page 1 of 1

Get ID of the record just added [SOLVED]

Posted: Wed Nov 17, 2004 8:19 am
by hairyjim
Hi all,

I'm doing a simple record insert into my MySQL table and immediatly after the record is added I want to use the auto-incremented ID column of the table

How do I get the ID of the record I just created?

I thought about selecting the very last record in the table but this could be dangerous if I have several users all hitting the submit button at the same time.

Could a little advice be offered?
(Yes I know don't eat yellow snow...yadda yadda yadda...you funny blighters)

Posted: Wed Nov 17, 2004 8:50 am
by phpScott

Posted: Wed Nov 17, 2004 9:13 am
by patrikG
[php_man]mysql_insert_id[/php_man]

Posted: Wed Nov 17, 2004 9:16 am
by hairyjim
Thats the one. mysql_insert_id is the way to go.

Cheers

Posted: Wed Nov 17, 2004 9:18 am
by patrikG
powerful this php manual is. agree you do, hairyjim?

Posted: Wed Nov 17, 2004 9:20 am
by hairyjim
Now you see I do agree that RTFM is the way to go but when you have no idea what subject it is under in TFM it makes it a little difficult to find the needle.

Posted: Wed Nov 17, 2004 9:25 am
by patrikG
Ah. :)