Forum Moderators: coopster
mysql_query($sSQL) or trigger_error(mysql_error());
$_SESSION['UserLoggedIn'] = mysql_insert_id();
As this isn't run in a transaction, isn't there the possibility that mysql_insert_id() could return an incorrect number. For example, if the the same insert ran a few hundreds of a millisecond after the first one?
[webmasterworld.com...]
also, why use the id as the value for 'UserLoggedIn', seems strange. If the login was successful then assign something to that var like 'true'. I actually never used a loggedin var in my session. If the user managed to login then the session should have some specific structured info in it, if it doesn't then it isn't a proper session that I created.
mysql_insert_id() returns the id of the row inserted in that page's previous insert, even if it is not the most recent insert.
But seeing is believing:
mysql_query($insertStatement);
sleep(30); # Ample time for another insert to occur?$rs = mysql_query($selectMaxID); # populate variable with your select statement
$array = mysql_fetch_array($rs);
echo "max id/insert id = " . $array[0] . "/" . mysql_insert_id() . "<br />";