Jump to content

How do you add multiple entries to db from form processing


phpdragon

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);
		}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.