Re: getting a auto-increment id back out of the database

From: Date: Fri, 09 May 2003 16:27:55 +0000
Subject: Re: getting a auto-increment id back out of the database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147039@lists.php.net to get a copy of this message
look up mysql_insert_id(), it will return the auto incremented field of the most recent statement. Here is how I use it: function get_jobid($array) { $statement = "insert into job(loanid, borrower) values ('$array[loanid]','$array[borrower]')"; $result = mysql_query($statement); if (!$result) echo "Database error occured...<br>"; return mysql_insert_id(); } On Fri, 2003-05-09 at 11:25, Amanda McComb wrote: > I have a query where I insert a bunch of stuff into a table, and it > creats a new record with a new id, auto-incremented by MySQL. Right after > I insert this, I want to instert some other stuff into another table using > the new id that was just created. Is there a way to get that id out > without doing a select that matches everything I just inserted (especially > since there could be multiple records with that same data?) > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Tom Woody Systems Manager, NationWide Flood Research, Inc. phone: 214-631-0400 x209 In a world without boundaries why do we need Gates and Windows?

« previous php.general (#147039) next »