INSERT duplicates records!!

admin

Administrator
Staff member
The following code is supposed to add a record to the table payment_details.

The problem I have is that it duplicates the record.

Eg customer x who has spent y and is due to be invoiced at z has 2 seperate payid records with identical data created as a result of the query. The payid number is an autoincremental and is the first column within the table.

I have checked the order of the values within the sql statement and they all appear to be as required.

As stated the only 'error' generated is the superfluous extra duplicate record which i dont want or need.


any pointers much appreciated

kind regards

rob


if (!$array["invoiceno"] || !$array["dateinv"] || !$array["name"] ||
!$array["amount"] ){
echo "<center>You need to complete <B>ALL</B> of the fields. Please go <a href=http://www.phpbuilder.com/board/archive/index.php/\"addinvoice.php\">back</a> and enter the required fields</center>";
exit;
}

$array ["custid"]= trim ($array["custid"]);
$array ["invoiceno"]= trim ($array["invoiceno"]);
$array ["dateinv"] = trim ($array["dateinv"]);
$array ["paydue"] = trim ($array["paydue"]);
$array ["paygot"]= trim ($array["paygot"]);
$array ["nextinv"]= trim ($array["nextinv"]);
$array ["custype"]= trim ($array["custype"]);
$array ["amount"] = trim ($array["amount"]);
$array ["name"] = trim ($array["name"]);
$array ["address"] = trim ($array["address"]);
$array ["city"] = trim ($array["city"]);
$array ["post_code"] = trim ($array["post_code"]);
$array ["telephone"] = trim ($array["telephone"]);
$array ["comments"] = trim ($array["comments"]);


$Host = "localhost";
$User = "robert";
$Password = "robert";
$DBName = "customer_records";

$Link = mysql_connect ($Host, $User, $Password);

$Query = "INSERT into payment_details values ('','$array[invoiceno]','$array[custid]','$array[dateinv]','$array[paydue]','','','$array[nextinv]','$array[custype]','$array[amount]','$array[name]')";

$Result = mysql_db_query ($DBName, $Query,$Link);




//print ("$Query\n");




if (mysql_db_query ($DBName, $Query, $Link )){
print ("Click <a href=http://www.phpbuilder.com/board/archive/index.php/\"getdata2.php\">here</a> to return to the main page \n");
}else {
print ("oh dear\n");
}

mysql_close ($Link);
 
Back
Top