Re: Getting last insert id?

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

 



$new_id = mysql_query('select last_insert_id()');

your can also user it within a query - eg

$sql = ' insert into related table parent_id, data , data2) values (last_insert_id(), 23, 45);

pete

hris Payne wrote:

Hi there everyone,

I use the below to insert some data into my database:


mysql_query ("INSERT INTO forummessages (Postedby, email, subject, message, ForumID, posted, parentid) VALUES ('$Postedby', '$email', '$subject', '$message', '$ForumID','$posted','$parentid')
");


But once it has done this, I need to get the id it has generated in the DB and then update that record with the id it generate, so how can I get the id from the above insert?

Any help would be greatly appreciated :-)

Regards

Chris

-- 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