Maybe someone here has experienced this because I can't find a cause or a solution...
The code snippet below shows a section from the "insert" page that users go to when submitting the main form. This page sets up a Javascript-controlled hidden form to pass back some values that we may need to keep for the next use of the form.
The problem is that when I check my database after inserting, I find more than one record each time.
I have checked and double checked and can find no reason.. Hence the "userdata->debug" checks in the code!
Thanks in advance
Richard
(Oh god, I hope its not something obvious!)
The code:
if ($userdata->debug) echo "<BR>Running the INSERT method\n";
$userdata->InsertNewRisk();
if ($userdata->debug) echo "<BR>Finished the INSERT method\n";
echo "<HEAD><TITLE>Insert RISK information...</TITLE></HEAD>\n";
echo "<BODY>\n";
echo "<FORM name=riskinsert method=post action=riskregform.php>\n";
echo "<input type=hidden name=type value=\"repeat\">\n";
echo "<input type=hidden name=sourcetype value=\"$sourcetype\">\n";
echo "<input type=hidden name=sourceref value=\"$sourceref\">\n";
echo "<input type=hidden name=sourcetitle value=\"$sourcetitle\">\n";
echo "<input type=hidden name=sourceitemref value=\"$sourceitemref\">\n";
echo "<input type=hidden name=sourceitemtitle value=\"$sourceitemtitle\">\n";
echo "</form>\n";
echo "<script language=Javascript>\n";
if ($userdata->LastInsertID)
{
echo " var repeatsource = false;\n";
echo " repeatsource = confirm(\"Your data has been stored as record number " . $userdata->LastInsertID . "\n\nDo you wish to add another RISK from the same SOURCE?\");\n";
echo " if (repeatsource)\n";
// Create new form with info to pass through...
echo " {\n";
echo " riskinsert.submit();\n";
echo " }\n";
echo " else\n";
echo " {\n";
echo " location.href(\"riskregform.php\");\n";
echo " }\n";
}
else
{
echo " alert(\"There was a problem adding your information to the database. Please contact the system administrator\");\n";
}
echo "</script>\n";
echo "</body>\n";
The InsertNewRisk() method is:
function InsertNewRisk()
{
$this->Connect();
$this->sqlquery = "insert into riskregister values ('', '1', now(), '', '', '$this->sourcetype', '$this->sourceref', '$this->sourcetitle', '$this->sourceitemref', '$this->sourceitemtitle', '$this->riskdescription', '$this->risktitle', '$this->topevent', '', '$this->riskadviser', '$this->riskowner', '$this->ctrcode', '$this->actcode', '', 'L')";
if ($this->debug) echo "<BR>Running query: ".$this->sqlquery;
$this->result = $this->RunQuery();
if ($this->debug) echo "<BR>Result was ".$this->result;
$this->LastInsertID = mysql_insert_id();
if ($this->debug) echo "<BR>Insert ID: ".$this->LastInsertID;
$this->Disconnect();
return;
}