No account yet?

Links

Home arrow Articles arrow Programming arrow Get the last inserted id in from php on a mysql database
Get the last inserted id in from php on a mysql database PDF Print E-mail
Tag it:
Delicious
blogmarks
Stumble
Furl it!
Digg
YahooMyWeb
Technorati
User Rating: / 1
PoorBest 

This is useful when you are working with multi page forms. If you want to update some information on one page, for one record, and then move to another page and update the same record some more you will need the primary key id field,

This is applicable to the case where the id field is an auto increment, which is the case seen in most circumstances. 

The code is really simple, lets take a look at how its done. 

 

This snippet inserts a value into a test table. The statement that gets the lastid is the mysql function last_insert_id(). We gave this an alias by saying as lastId

The result is looped as an associative array, and wallah, we have the id of the last insert.

Comments
Search
Only registered users can write comments!
Last Updated ( Thursday, 18 September 2008 )
 
< Prev   Next >