Re: [PHP-DB] newbie - last_insert_id() with mysql

2002-12-12 Thread Peter Beckman
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
[EMAIL PROTECTED] http://www.purplecow.com/
---

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




Re: [PHP-DB] newbie - last_insert_id() with mysql

2002-12-12 Thread 1LT John W. Holmes
 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...


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