PDA

View Full Version : Quick PHP/MySQL Help


Test Zero
18 Mar 2009, 18:30
If I add a new entry do a database, how do I then find its primary key?

Bear in mind that in some cases, the primary key is the only unique value (i.e. adding John then "SELECT * WHERE Name=John" would not work if there are other Johns.

bloopy
18 Mar 2009, 20:42
http://dev.mysql.com/doc/refman/5.1/en/getting-unique-id.html

Test Zero
18 Mar 2009, 22:07
Thankyou darling.

SupSuper
18 Mar 2009, 23:47
$id = mysql_result( mysql_query( 'SELECT LAST_INSERT_ID()' ), 0, 0 );