RE: [PHP] INSERT_ID() & INSERT problem

From: Date: Mon, 17 Jun 2002 02:32:26 +0000
Subject: RE: [PHP] INSERT_ID() & INSERT problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-102455@lists.php.net to get a copy of this message
> What do you meant that the second query has an auto_increment column, > but only if nothing was entered? It looks like you're putting $value > into the first column, so an auto_increment column isn't going to be > generated. That's why your MySQL_insert_id() is returning the value from > your first query. You have to insert NULL, or leave the column out of > your insert statement, in order for a number to be assigned by > auto_increment. [César L. Aracena] Thanks. That's fine, but what I'm trying to do here, is to let the user insert one of two users: a) A new user which will have an auto-generated id or b) An existing user which will be added for the first time to this "new" management system. So basically, what I need is to be able to tell the script which one of the previous options is true. Right now, I'm trying to make an IF selection, like: if ($value == '') { // scripts queries with NULL } else if ($value != '') { // script queries with $value } Does this make any sense? The only problem, is that the actual query doesn't work and that's syntax problem (I think) due to new-to-me code. I posted the query in a mail called "Tricky Query". > > ---John Holmes... > > > -----Original Message----- > > From: César Aracena [mailto:icaam@icaam.com.ar] > > Sent: Sunday, June 16, 2002 7:57 PM > > To: 'PHP General List' > > 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 > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#102455) next »