Re: newbie - last_insert_id() with mysql

From: Date: Thu, 12 Dec 2002 19:08:29 +0000
Subject: Re: newbie - last_insert_id() with mysql
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-24098@lists.php.net to get a copy of this message
> mysql_insert_id() is a PHP function, not a MYSQL function. You are also > missing a close quote on your insert string. So you have to do it like > this: Correct, but LAST_INSERT_ID() is a MySQL function.... which is what he's using... > $sql2 = "insert into acl (adminId,transportId,securityId) values ('$userid',".last_insert_id().",'1')"; So, no, you're trying to use a MySQL function here in PHP code. The original syntax was correct. > $lastid = mysql_insert_id(); > $sql2 = "insert into acl (adminId,transportId,securityId) values ('$userid',".$lastid.",'1')"; > > which is the same as: > > $lastid = mysql_insert_id(); > $sql2 = "insert into acl (adminId,transportId,securityId) values ('$userid',$lastid,'1')"; Both of those are correct, too, if you want to use the PHP function. > > $sql1 = "insert into transport (domain,transport) values > > ('$domain','$transport')"; > > $sql2 = "insert into acl (adminId,transportId,securityId) values > > ('$userid',last_insert_id(),'1'"; > > > > mysql_query($sql1); > > mysql_query($sql2); You're missing a closing paranthesis on the end of the second SQL statement. That is probably what's causing your error. In the future, use mysql_error() to find out why it's failing... mysql_query($query) or die("Error in $query: " . mysql_error()); ---John Holmes...

« previous php.db (#24098) next »