...

View Full Version : duplicate error



minkoko
08-20-2012, 05:38 AM
Hello all my bro
i found some error on my shopping cart order statement
this error is Query fail Duplicate entry '1179' for key 'PRIMARY'


and my code is

$memberId = $_POST['memberid'];
if ($orderId) {
for ($i = 0; $i < $numItem; $i++) {
$tdate = date("Y-m-d H:i:s");// current date
$ddate = date('Y-m-d', strtotime("+4 month"));
$sql = "INSERT INTO tbl_order(orderid,item_id,item_price,orderdate,deldate,userid, item_qty,item_shipfees,item_discountprice,ototalprice,orderstatus)
VALUES ($orderId, {$cartContent[$i]['item_id']},{$cartContent[$i]['cprice']},NOW(),$ddate,$memberId,{$cartContent[$i]['ctqty']},
{$cartContent[$i]['item_shipfees']},{$cartContent[$i]['item_discountfees']},$hidtotalprice,1)";

$result = dbQuery($sql);

}
echo "I found the errorError Line" . mysql_errno(); //error slove

// update product stock
for ($i = 0; $i < $numItem; $i++) {
$sql = "UPDATE tbl_item SET item_qty = item_qty - {$cartContent[$i]['ctqty']}
WHERE item_id = {$cartContent[$i]['item_id']}";
$result = dbQuery($sql);
}


// then remove the ordered items from cart
for ($i = 0; $i < $numItem; $i++) {
$sql = "DELETE FROM tbl_cart
WHERE cardid = {$cartContent[$i]['cardid']}";
$result = dbQuery($sql);
}
}

Thanks for appreciate

MarkR
08-20-2012, 10:43 AM
Order id in your target table is a primary key and must be unique, you must be trying to insert another row with a primary key which already exists.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum