Re: getting ID

From: Date: Mon, 20 Aug 2001 10:20:20 +0000
Subject: Re: getting ID
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-11537@lists.php.net to get a copy of this message
mysql_insert_id([resource link_identifier]) returns the value of the auto_increment field for the previous INSERT query. It will return 0 if there is not an auto_increment field. If the link_identifier is not specified, the last opened connection is used. So, use $id = mysql_insert_id(); directly after your $result = mysql_query($query); operation (where $query is an INSERT query) to pull the id value you have just auto inserted back out. Ian. Manual page: http://www.php.net/manual/en/function.mysql-insert-id.php Crosswalkcentral <support@crosswalkcentral.net> wrote in message news:20010819185855.60275.qmail@pb1.pair.com... > I tried this and it gave me an error. > > Will this > > $id = mysql_insert_id(); > > allow me to pull out the id? > > > -- > Cross Walk Central > www.crosswalkcentral.net > Support Center > Your Web Hosting Community! > > "Cynic" <cynic@mail.cz> wrote in message > news:5.1.0.14.2.20010819203852.00b4d260@mail.cz... > > At 19:19 8/19/2001, CrossWalkCentral wrote the following: > > -------------------------------------------------------------- > > >I have a script where I submit user data to the database in my script I > need > > >to get the id # how can I do this w/o creating a query that does the > > >following considering that user could have 10 other entires. > > > > mysql_query("insert into ..."); > > $id = mysql_insert_id(); > > > > > > >// Request info > > >$result = mysql_query( > > >"SELECT * FROM supportsys WHERE email = $email"); > > >if (!$result) { > > >echo("<P>Error performing query: " . > > >mysql_error() . "</P>"); > > >exit(); > > >} > > > > > > > > >I basicly need to get the id$ of the record just entered > > >-- > > >Cross Walk Central > > >www.crosswalkcentral.net > > >Support Center > > >Your Web Hosting Community! > > > > > > > > > > > > > > >-- > > >PHP Database Mailing List (http://www.php.net/) > > >To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > >For additional commands, e-mail: php-db-help@lists.php.net > > >To contact the list administrators, e-mail: php-list-admin@lists.php.net > > ------end of quote------ > > > > > > cynic@mail.cz > > ------------- > > And the eyes of them both were opened and they saw that their files > > were world readable and writable, so they chmoded 600 their files. > > - Book of Installation chapt 3 sec 7 > > > >

« previous php.db (#11537) next »