Re: determine the primary key after adding a row to a table (mysql)

From: Date: Wed, 24 Apr 2002 18:05:11 +0000
Subject: Re: determine the primary key after adding a row to a table (mysql)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-18785@lists.php.net to get a copy of this message
I encountered something similar. Here is a snippet of code: $tdate=date("Y\\-m\\-d"); $time=date("G\\:i\\:s"); $query="insert into trackinginfo (IP_Address, username, date, Time, Processed, CommentFlag) values ('$REMOTE_ADDR', '$username', '$tdate', '$time', 'N', '$commentExists')"; mysql_query($query) or die(mysql_error()); //RecordID is an auto incrementing primary key. $query="select RecordID from trackinginfo where IP_Address='$REMOTE_ADDR' and username='$username' and date='$tdate' and Time= '$time'"; //used those variables as they are static for the page. And yes, that is a bit of overkill you see there. $result = mysql_query($query) or die(mysql_error()); $dummyvar = mysql_fetch_object($result); $sid=$dummyvar->RecordID; "Cj" <calistusj@hotmail.com> wrote in message news:20020424171846.31802.qmail@pb1.pair.com... > is there any way to determine the primary key of a row after it's added to a > table in mysql? > > i need to do this because i have another table which requires the id from > one table as a foreign key. > >

« previous php.db (#18785) next »