Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-20-2012, 05:38 AM   PM User | #1
minkoko
New Coder

 
Join Date: Aug 2010
Location: myeik
Posts: 72
Thanks: 4
Thanked 5 Times in 5 Posts
minkoko can only hope to improve
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
minkoko is offline   Reply With Quote
Old 08-20-2012, 10:43 AM   PM User | #2
MarkR
New Coder

 
Join Date: Sep 2011
Posts: 80
Thanks: 0
Thanked 13 Times in 12 Posts
MarkR is an unknown quantity at this point
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.
__________________
Web Design Newcastle
MarkR is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:49 PM.


Advertisement
Log in to turn off these ads.