How to get current ID when inserting in mySQL

I created a table with columns ID, Message and Author. ID is int, primary key, unique for each entry. Now when I add new entry into database i would like to know what ID was assigned to it. How can that be done?

Using SELECT ID from… WHERE Author LIKE … AND Message LIKE …
is not OK because there can be 2 entries with the same content, so I would get wrong ID.

Any ideas ?

mysql_insert_id() will do the job!

mysql_insert_id – Get the id generated from the previous INSERT operation

I use it like this after a submit:
$new_id_number = mysql_insert_id();


it worked :smiley:


Sure… glad it worked!