Jump to content

How do you add multiple entries to db from form processing


Recommended Posts

I have made a shopping cart type application, when it comes to adding all the items into the db after finalising the order, how do you get it to loop thru and add each entry as a seperate entity

 

eg

item1    item1price  item1qty

item2    item2price  item2qty etc etc

 

this is the code I am trying but it only adds the last item in the cart so I dont seem to have it looping till all items are added, could someone please show me how to get it to add all items.

 

current code

// declare order product variables
$ordersql="SELECT orderID FROM orders WHERE userID='$userID' ORDER BY orderID DESC LIMIT 1";
		$resultorder=mysql_query($ordersql);
		$result_row=mysql_fetch_array($resultorder);
		$thisID=$result_row["orderID"];
$orderTable=$userID."_orders";
for ($basket_counter=0;$basket_counter<$ses_basket_items;$basket_counter++){
      		$price=sprintf("%01.2f",$ses_basket_price[$basket_counter]);
      		$quantity=$ses_basket_amount[$basket_counter];
		$code=$ses_basket_stockcode[$basket_counter];
		$itemID=$ses_basket_id[$basket_counter];
      		$product=$ses_basket_name[$basket_counter];
		$unit=sprintf("%01.2f",($price/$quantity));
// add item to users order table
$sql="INSERT INTO $orderTable (orderID, name, productID, quantity, stockcode, price) VALUES ('$thisID', '$product', '$itemID', '$quantity', '$code', '$unit')";
		$result=mysql_query($sql);
		}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.