retrieve autoincrement value in PHP
I want to display an autoincrement value after a record has been added in a MySQL database. In MySQL I can do :
INSERT INTO table (ID,field) VALUES(NULL,'text');
SELECT LAST_INSERT_ID();
However how do I get this value on screen in a PHP-program?
The update in PHP-code looks like:
$table_add = "INSERT INTO table (ID,field) VALUES (NULL, '$field')";
$bool = mysql_query($table_add);
and than I want to show the record-ID like :
echo "Thanks $text, record ID: $ID";
If i do a seperate query, the last_insert_ID value renders 0 (zero), so it must be done within the same query. What should the query look like and how to display the result in PHP?
Subject
Written By
Posted
retrieve autoincrement value in PHP
May 30, 2005 06:12AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.