Re: Getting last record ID created from DB

From: Date: Sat, 17 Mar 2007 05:34:46 +0000
Subject: Re: Getting last record ID created from DB
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-250743@lists.php.net to get a copy of this message
Janet Valade wrote:
Jeff wrote:
Is there a way to get the last Record # created by the DB.
...
what code could I add here to make the following line work? echo "REMEMBER your USER ID# you will need it when creating Characters!! It is: $user_id"; <----- I want to show the "user_id" just created here. Thanks in advance!
The function mysql_insert_id will return the previous id inserted. http://us3.php.net/manual/en/function.mysql-insert-id.php Janet but to use this, you need to have the user_id field name and value omitted from the insert statement.
Other wise it enters a null value in the field, basically overriding the purpose of the auto_increment setting. Once you have completed the the insert, run this command http://www.php.net/mysql_insert_id This will then give you the LAST INSERT ID for your connection to the DB. Hope it helps

« previous php.general (#250743) next »