Re: newbie - last_insert_id() with mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

$sql2 = "insert into acl (adminId,transportId,securityId) values ('$userid',".last_insert_id().",'1')";

Notice the "string".function()."string" -- this basically puts the return
value of the function (in this case, the last ID inserted) into the string.
If it was a MySQL function, you'd have done it correctly; however
mysql_insert_id() is a PHP function and thus you must have PHP run the
function ouside of the string instead of passing the function as part of
the string.

The above is the same as doing this:

$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')";

But use the first example I gave you.

Peter

On Thu, 12 Dec 2002, Max Clark wrote:

> Hi-
>
> I am trying to insert information into mysql based with the sql queries
> below. When I run this insert from the mysql console everything works
> correct, however, when I run this through php the second sql query doesn't
> execute (I'm assuming there is a problem with the last_insert_id()).
>
> I have tried changing the "last_insert_id()" to a "mysql_insert_id()"
> function with no success?
>
> How do I get this to work?
> Thanks in advance,
> Max
>
> $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);
>
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

---------------------------------------------------------------------------
Peter Beckman                                                  Internet Guy
beckman@purplecow.com                             http://www.purplecow.com/
---------------------------------------------------------------------------

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux