Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: duplicate error

  1. #1
    New Coder
    Join Date
    Aug 2010
    Location
    myeik
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 5 Posts

    duplicate error

    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
    Code:
    $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

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    80
    Thanks
    0
    Thanked 13 Times in 12 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •