I have a SQL database which i use to store some info and every record has a unique id generated by the database. MY program is written in flash and runs over the web, the program runs fine and it inserts records into the database and pulls the idnumber of the last record and displays it for user, my question is though how do i handle multiple concurrent entries because the program will be used by multiple users and chances are there will be concurrent inserts into the database so how would i be able to identify the correct unique id numbers for users
here is the code for inserting into the database
$query = "INSERT into $tablename (grade,school,country) VALUES ('$datarray[0]','$datarray[1]','$datarray[2]')";
$result = mysql_query($query)
or die("no rows selected");
and after that i load another php file on the second in my flash file to pull the id for that record and display it here is the code
$query = "SELECT max(id) from $tablename";
$result = mysql_query($query)
or die("no rows selected");
$row = mysql_fetch_array($result); // extracts one row
echo "id=$row[0]";
what do i need to do to get the correct id for that record?