Im writing a very basic script which takes input from a form puts it into a database. My question is: I have created a field in the db called "id" which is auto increment. After creating a new record, how do I figure out what the "id" was of the newly created record so I can put it into a variable?
Hi, Not sure if this could help - but after you add a record, you may do a query to give you id from the last record in your database. That way you can get the id and than store it in your variable! Hope this helps you!
After you insert data into the database. // mysql_query("INSERT INTO .... "); $lastId = mysql_insert_id(); echo "Last id to be inserted: " . $lastId; Code (markup):
The practice that I follow generally in scenarios where concurrent inserts are happening is to generate a unique field for each entry and then query using that unique field. This mainly helps where a thread has to wait due to lock acquired by another thread or due to any other reason for a matter.