I wrote a web application that uses a PHP script to create a more-or-less empty record in a database, then a Perl script to update that record, filling in all of the fields. What I see happening occasionally is that an initialized "empty" record will be re-used by another user. I though that wasn't supposed to happen with the mysql_insert_id() function. Although I may be laying blame in the wrong direction. Here is the PHP code that creates a new record:
// create a new record now, so there are no conflicting App_ID's
$query = "insert into $appTable (EmpID, FIBDE) values ('$EmpID', '$FIBDE')";
$result = mysql_query($query) or die("Cannot execute $query: " . mysql_errno().": ".mysql_error());
// revised Aug 9 2002 to hopefully solve missing app mystery
if (mysql_affected_rows()>0)
{
$App_ID=mysql_insert_id();
error_log("New Application: EmpID $EmpID - App_ID $App_ID - FIBDE $FIBDE");
}
else
{
error_log("WARNING: New application not initialized properly");
die("Application unable to initialize. Contact admin.");
}
$App_ID is an autoincrement column. $EmpID is grabbed from a cookie and associates each employee with an application.
Then $App_ID gets passed in a hidden form field which gets submitted to a Perl CGI. That CGI includes a statement to update the database where App_ID= the hidden form field value of $App_ID.
The problem, or rather the symptom I am seeing, is that sometimes an employee fills out an application, it goes into the database, but when viewing a report of applications, their application is associated with the wrong employee. I hope this makes sense, and any help would be appreciated.