INSERT_ID() & INSERT problem

From: Date: Sun, 16 Jun 2002 23:57:11 +0000
Subject: INSERT_ID() & INSERT problem
Groups: php.general 
Request: Send a blank email to php-general+get-102434@lists.php.net to get a copy of this message
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 (#102434) next »