Forum Moderators: open

Message Too Old, No Replies

Creates Multiple Records

Dreamweaver Insert Record

         

swanside

3:24 pm on Dec 2, 2007 (gmt 0)

10+ Year Member



Hello again.
I have just made an insert record using the wizard in Dreamweaver, but, upon pressing the submit button, when I look in the database in MyPHPAdmin, it has duplicated the record two or three times?
Any ideas please?

Cheers
Paul.

LifeinAsia

5:32 pm on Dec 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Posting your relevant code may help...

swanside

6:14 pm on Dec 3, 2007 (gmt 0)

10+ Year Member



Sorry, Here is the code.
<?php require_once('Connections/Local.php');?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc())? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue!= "")? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue!= "")? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue!= "")? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue!= "")? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue!= "")? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO customer (Customer_Name, Billing_Address, Customer_Note, Locked) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['Customer_Name'], "text"),
GetSQLValueString($_POST['Billing_Address'], "text"),
GetSQLValueString($_POST['Customer_Note'], "text"),
GetSQLValueString($_POST['Locked'], "int"));

mysql_select_db($database_Local, $Local);
$Result1 = mysql_query($insertSQL, $Local) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO job (Order_Date, File_No, Job_No, Customer_ID, Order_Time, Contract, Order_Site_Address, Job_Description, VAT, Invoice_Printed, Invoice_Printing_Date, Invoice_Tax_Date, Payment_Received, Job_Finished, CustomerRef, Customer_Name, Payment_Due_date, Payment_Date, Locked) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Order_Date'], "date"),
GetSQLValueString($_POST['File_No'], "text"),
GetSQLValueString($_POST['Job_No'], "int"),
GetSQLValueString($_POST['Customer_ID'], "int"),
GetSQLValueString($_POST['Order_Time'], "text"),
GetSQLValueString($_POST['Contract'], "text"),
GetSQLValueString($_POST['Order_Site_Address'], "text"),
GetSQLValueString($_POST['Job_Description'], "text"),
GetSQLValueString($_POST['VAT'], "double"),
GetSQLValueString($_POST['Invoice_Printed'], "int"),
GetSQLValueString($_POST['Invoice_Printing_Date'], "date"),
GetSQLValueString($_POST['Invoice_Tax_Date'], "date"),
GetSQLValueString($_POST['Payment_Received'], "int"),
GetSQLValueString($_POST['Job_Finished'], "int"),
GetSQLValueString($_POST['CustomerRef'], "text"),
GetSQLValueString($_POST['Customer_Name'], "text"),
GetSQLValueString($_POST['Payment_Due_date'], "date"),
GetSQLValueString($_POST['Payment_Date'], "date"),
GetSQLValueString($_POST['Locked'], "int"));

mysql_select_db($database_Local, $Local);
$Result1 = mysql_query($insertSQL, $Local) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO job (Order_Date, File_No, Order_Time, Contract, Order_Site_Address, Job_Description, CustomerRef, Customer_Name) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Order_Date'], "date"),
GetSQLValueString($_POST['File_No'], "text"),
GetSQLValueString($_POST['Order_Time'], "text"),
GetSQLValueString($_POST['Contract'], "text"),
GetSQLValueString($_POST['Order_Site_Address'], "text"),
GetSQLValueString($_POST['Job_Description'], "text"),
GetSQLValueString($_POST['CustomerRef'], "text"),
GetSQLValueString($_POST['Customer_Name'], "text"));

mysql_select_db($database_Local, $Local);
$Result1 = mysql_query($insertSQL, $Local) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO job (Order_Date, File_No, Order_Time, Contract, Order_Site_Address, Job_Description, CustomerRef, Customer_Name) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Order_Date'], "date"),
GetSQLValueString($_POST['File_No'], "text"),
GetSQLValueString($_POST['Order_Time'], "text"),
GetSQLValueString($_POST['Contract'], "text"),
GetSQLValueString($_POST['Order_Site_Address'], "text"),
GetSQLValueString($_POST['Job_Description'], "text"),
GetSQLValueString($_POST['CustomerRef'], "text"),
GetSQLValueString($_POST['Customer_Name'], "text"));

mysql_select_db($database_Local, $Local);
$Result1 = mysql_query($insertSQL, $Local) or die(mysql_error());

$insertGoTo = "jobsearch1.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?'))? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style5 {font-style: italic; font-size: 16px;}
body,td,th {
color: #00FF00;
}
body {
background-color: #000000;
}
-->
</style>
</head>

<body>
<div align="center"><strong>
<?php
$colname_CSDRecordset = "-1";
if (isset($_GET['recordID'])) {
$colname_CSDRecordset = (get_magic_quotes_gpc())? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Local, $Local);
$query_CSDRecordset = sprintf("SELECT Job_No, Engineer_Name, Paying_Rate, Working_Hrs FROM labour WHERE Job_No = '%s'", $colname_CSDRecordset);
$CSDRecordset = mysql_query($query_CSDRecordset, $Local) or die(mysql_error());
$row_CSDRecordset = mysql_fetch_assoc($CSDRecordset);
$totalRows_CSDRecordset = mysql_num_rows($CSDRecordset);

$colname_CSMRecordset = "-1";
if (isset($_GET['recordID'])) {
$colname_CSMRecordset = (get_magic_quotes_gpc())? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Local, $Local);
$query_CSMRecordset = sprintf("SELECT Job_No, Quantity, Unit_Price, Additional_Cost, Description FROM material WHERE Job_No = '%s'", $colname_CSMRecordset);
$CSMRecordset = mysql_query($query_CSMRecordset, $Local) or die(mysql_error());
$row_CSMRecordset = mysql_fetch_assoc($CSMRecordset);
$totalRows_CSMRecordset = mysql_num_rows($CSMRecordset);

$colname_LTRecordset = "-1";
if (isset($_GET['recordID'])) {
$colname_LTRecordset = (get_magic_quotes_gpc())? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Local, $Local);
$query_LTRecordset = sprintf("SELECT Paying_Rate * Working_Hrs FROM `labour` WHERE Job_No = '%s'", $colname_LTRecordset);
$LTRecordset = mysql_query($query_LTRecordset, $Local) or die(mysql_error());
$row_LTRecordset = mysql_fetch_assoc($LTRecordset);
$totalRows_LTRecordset = mysql_num_rows($LTRecordset);

$colname_MTRecordset = "-1";
if (isset($_GET['recordID'])) {
$colname_MTRecordset = (get_magic_quotes_gpc())? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Local, $Local);
$query_MTRecordset = sprintf("SELECT Quantity * Unit_Price FROM `material` WHERE Job_No = '%s'", $colname_MTRecordset);
$MTRecordset = mysql_query($query_MTRecordset, $Local) or die(mysql_error());
$row_MTRecordset = mysql_fetch_assoc($MTRecordset);
$totalRows_MTRecordset = mysql_num_rows($MTRecordset);

$colname_DSRecordset = "-1";
if (isset($_GET['recordID'])) {
$colname_DSRecordset = (get_magic_quotes_gpc())? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Local, $Local);
$query_DSRecordset = sprintf("SELECT Order_Date, Job_No, Order_Time, Order_Site_Address, Job_Description, Invoice_Printed, Invoice_Printing_Date, Invoice_Tax_Date, Payment_Received, Job_Finished, Customer_Name, Payment_Due_date, Payment_Date FROM job WHERE Job_No = %s", $colname_DSRecordset);
$DSRecordset = mysql_query($query_DSRecordset, $Local) or die(mysql_error());
$row_DSRecordset = mysql_fetch_assoc($DSRecordset);
$totalRows_DSRecordset = mysql_num_rows($DSRecordset);

$maxRows_addcost = 10;
$pageNum_addcost = 0;
if (isset($_GET['pageNum_addcost'])) {
$pageNum_addcost = $_GET['pageNum_addcost'];
}
$startRow_addcost = $pageNum_addcost * $maxRows_addcost;

$colname_addcost = "-1";
if (isset($_GET['recordID'])) {
$colname_addcost = (get_magic_quotes_gpc())? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_Local, $Local);
$query_addcost = sprintf("SELECT Quantity * Unit_Price + (Quantity * Unit_Price * Additional_Cost / 100) FROM `material` WHERE Job_No = '%s'", $colname_addcost);
$query_limit_addcost = sprintf("%s LIMIT %d, %d", $query_addcost, $startRow_addcost, $maxRows_addcost);
$addcost = mysql_query($query_limit_addcost, $Local) or die(mysql_error());
$row_addcost = mysql_fetch_assoc($addcost);

if (isset($_GET['totalRows_addcost'])) {
$totalRows_addcost = $_GET['totalRows_addcost'];
} else {
$all_addcost = mysql_query($query_addcost);
$totalRows_addcost = mysql_num_rows($all_addcost);
}
$totalPages_addcost = ceil($totalRows_addcost/$maxRows_addcost)-1;
?>
</strong> <strong><span class="style5">Leymac Engineering Ltd Job Database</span></strong></div>
<p><strong><img src="as-ppt-anim-brass-cogs.gif" width="200" height="150" /></strong></p>
<p>&nbsp;</p>

<form method="post" name="form1" action="<?php echo $editFormAction;?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Order Date:</td>
<td><input type="text" name="Order_Date" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">File No:</td>
<td><input type="text" name="File_No" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Order Time:</td>
<td><input type="text" name="Order_Time" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Contract:</td>
<td><input type="text" name="Contract" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Job Location:</td>
<td><textarea name="Order_Site_Address" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Job Description:</td>
<td><textarea name="Job_Description" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Customers Ref:</td>
<td><input type="text" name="CustomerRef" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Customers Name:</td>
<td><input type="text" name="Customer_Name" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

LifeinAsia

6:27 pm on Dec 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I don't know much about PHP, but from what I see, you have 1 insert into the Customer table and 3 inserts into the Job table with identical IF statements. So yes, I would expect to see 3 almost identical rows in Job for each form submission with this code.

swanside

7:27 pm on Dec 4, 2007 (gmt 0)

10+ Year Member



Opps, Didnt see that, will look at that.
Cheers
Paul.