RE: [PHP] INSERT_ID() & INSERT problem

From: Date: Mon, 17 Jun 2002 01:00:34 +0000
Subject: RE: [PHP] INSERT_ID() & INSERT problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-102442@lists.php.net to get a copy of this message
> what are you trying to do with this? What were you expectibng?: > $id2 = mysql_insert_id(); [Cesar Aracena] I just need the first query's insert_id() to be able to insert it into the second table. The second insert_id() is to show the user's actual given id. > > ----- Original Message ----- > From: "César Aracena" <icaam@icaam.com.ar> > To: "'PHP General List'" <php-general@lists.php.net> > Sent: Sunday, June 16, 2002 6:57 PM > Subject: [PHP] INSERT_ID() & INSERT problem > > > Hi all, > > I'm having problems adding a new user into two tables. Actually, these > are two different tables, with different field in them. In the first > one, the user is added with an auto_increment id in order to be > recognized as a user for the web interface with a level of 1. In the > second table, the same user is added for record keeping, in which one of > its fields is the id auto-generated in the last query. I am able to > accomplish the first step of the process and insert the user into the > web interface table, but when it comes to the second part, nothing > happens. > > Also, I'm using the LAST_INSERT_ID() to fetch the auto-generated number > at step 1 and that seems ok (if I print it on the screen, it gives me > the right one) but when it comes to get the mysql_insert_id() at step 2, > it also gives me the auto-generated number from the first step. ??? > > I have the following: > > $query1 = "INSERT INTO table1 VALUES (NULL, '".$value."', > password('".$value."'), '1', '".$value."', > '".$value."')"; > $result1 = mysql_query($query1); > > echo "1st ADDED OK"; > > if ($result1) > { > $query2 = "INSERT INTO table2 VALUES ('".$value."', > '".$value."', > LAST_INSERT_ID(), '".$value."', '".$value."')"; > > $result2 = mysql_query($query2); > $id2 = mysql_insert_id(); > > echo "2nd ADDED OK with id = $id2"; > } > > Also, the first value entered into the second table, it's also > auto_increment but only if no input was made. ¿Is this ok? > > Thanks in advance, > > Cesar Aracena <mailto:webmaster@icaam.com.ar> > CE / MCSE+I > Neuquen, Argentina > +54.299.6356688 > +54.299.4466621 >

« previous php.general (#102442) next »