Unanswered: Retrieving an 'id' from a recent table entry?
If I add a row to a MySQL table that has an auto-incrementing 'id' field, how do I get the 'id' that was created for this entry and be sure that it's correct?
I could find the max 'id' before entering the row and then just add one, but it's possible that someone else could enter something between my retrieving the max id and entering the row (entries are done via a public web form). I could get the max after I enter, but the same problem arises.
I couldn't find the row that has all the same values as what I just entered, because the 'id' is the sole attribute of the primary key so it's possible for two rows to be exactly the same except for their id.
So, to recap, after executing the following:
mysql_query("INSERT INTO table (col2,col3,etc) VALUES (val2,val3,etc)",$conn)
I want to get the id that was generated for that insertion.