0

Possible Duplicate:
php/MySQL insert row then get 'id'

I have an inset command such as

insert (name) values($name);

I have id column as autoincrement. How can I get the id of the inserted record after inserting.

Community
  • 1
  • 1
Adham
  • 63,550
  • 98
  • 229
  • 344

2 Answers2

0
insert (name) values($name);
SET @lastid = LAST_INSERT_ID();
select blah_blah from table where id = @lastid;

To get that back into php, you do a normal mysql select on it like this:

select @lastid;
Billy Moon
  • 57,113
  • 24
  • 136
  • 237
0

For mysql you can use mysql_insert_id to get the id of the last inserted row.

Twelve47
  • 3,924
  • 3
  • 22
  • 29