Hi i have a insert problem which i can't find a solution for. The problem are when i try to make an insert it seems to occur twice, i.e. i get double data in the table.
I have a form with several fields both input and select, some code like this:
print "<form method=\"POST\" name=\"main\" action=\"add_handler.php\" onSubmit=\"return verify();\">";
$Dato = date("d.m.Y");
print "<table width=\"1057\" height=\"134\" border=\"1\"><tr>";
print "<td width=\"92\" height=\"7\" CLASS = \"Tableheader\">Date</td>";
print "<td width=\"141\" height=\"7\" CLASS = \"Tableheader\">Signature</td>";
print "<td width=\"141\" height=\"7\" CLASS = \"Tableheader\">Project No</td>";
print "<td width=\"192\" height=\"7\" CLASS = \"Tableheader\">Sub Project No</td>";
print "<td width=\"215\" height=\"7\" CLASS = \"Tableheader\">Document No</td></tr>";
print "<tr><td width=\"92\" height=\"11\"><input type=\"text\" name=\"Dato\" value=\"$Dato\" size=\"20\"></td>";
print "<td width=\"141\" height=\"11\"><select size=\"1\" name=\"Signature\">";
$signature = "SELECT Signature.SigID, Signature.Name
FROM Signature
ORDER BY Signature.Name;";
$query_signature = mysql_query($signature, $connection);
while ($row_signature = mysql_fetch_object($query_signature))
{
if($row_signature->SigID == $row->SigID)
{
print "<option selected value=\"$row_signature->SigID\">$row_signature->Name</option>";
}
else
{
print "<option value=\"$row_signature->SigID\">$row_signature->Name</option>";
}
}
print "</select></td>";
...
more code for fields and options boxes
...
print "</table>";
print "<INPUT TYPE=\"submit\" VALUE=\"Insert Project</form>";
The insert code (add_handler is like this):
$connection = mysql_connect("<servers ip address>", "<user name>", "<password>")
or die("Could not connect to database");
mysql_select_db("<database name>", $connection)
or die("Could not find database");
$Dato = $_POST['Dato'];
$Signature = $_POST['Signature'];
$ProjectNo = $_POST['ProjectNo'];
$SubProjectNo = $_POST['SubProjectNo'];
$DocumentNo = $_POST['DocumentNo'];
$Consignee = $_POST['Consignee'];
$Consignor = $_POST['Consignor'];
$ShippingAgent = $_POST['ShippingAgent'];
$ShippingRef = $_POST['ShippingRef'];
$DeclarationNo = $_POST['DeclarationNo'];
$ArticleNo = $_POST['ArticleNo'];
$ProcType = $_POST['ProcType'];
$Goods = $_POST['Goods'];
$ReExportDate = $_POST['ReExportDate'];
$Weight = $_POST['Weight'];
$Comment = $_POST['Comment'];
$AwbNo = $_POST['AwbNo'];
$id = $_POST['id'];
$chkCardboard = $_POST['chkCardboard'];
$chkFibreboard = $_POST['chkFibreboard'];
$chkItem = $_POST['chkItem'];
$chkPallet = $_POST['chkPallet'];
$chkCrate = $_POST['chkCrate'];
$chkPlywood = $_POST['chkPlywood'];
$chkContainer = $_POST['chkContainer'];
$chkSkid = $_POST['chkSkid'];
$Dato = format_date($Dato);
$ReExportDate = format_date($ReExportDate);
$qfreight = "INSERT INTO Freight
VALUES(NULL,'$Dato', '$Signature', '$ProjectNo', '$SubProjectNo', '$DocumentNo', '$Consignee', '$Consignor',
'$ShippingAgent', '$ShippingRef', '$DeclarationNo', '$ArticleNo', '$ProcType', '$Goods', '$Weight', '$Comment', ";
if($ReExportDate=="")
{
$qfreight .= "'$ReExportDate'";
}else
{
$qfreight .= "NULL";
}
$qfreight .= ", '$AwbNo');";
print $qfreight;
if(!$query_result = mysql_query($qfreight, $connection))
handle_mysql_error($connection);
mysql_close($connection);
Anyone have any clue?
Paal