Hi guys Good day, how to insert multiple data in the database? when i insert data that has multiple orders, only one item is inserted in the database. pls help me to put this on loop.
Heres the code i use:
foreach ($_SESSION["cart_array"] as $each_items){
$item_id = $each_items['item_id'];
$quantity = $each_items['quantity'] ;
$sql = mysql_query("SELECT * FROM product WHERE id = '$item_id'");
while($row = mysql_fetch_array($sql)){
$product_name = $row['name'];
$price = $row['price'];
$total_price = $price * $quantity;
mysql_query("INSERT INTO customer_order(
id,quantity,item_id,
total_price,shipping_address,
shipping_date,customer_id)
VALUES ('','$quantity','$item_id','$total_price',
'','',
'$lastId')") or die (mysql_error());
}
}
Heres what i did but it gives me syntax error, pls help me to do the proper looping for this. thanks
foreach ($_SESSION["cart_array"] as $each_items){
$item_id = $each_items['item_id'];
$item_id_count = count($item_id) ;
$quantity = $each_items['quantity'] ;
$sql = mysql_query("SELECT * FROM product WHERE id = '$item_id'");
while($row = mysql_fetch_array($sql)){
$product_name = $row['name'];
$price = $row['price'];
$total_price = $price * $quantity;
foreach($i=0,$i < $item_id_count,$i++){
mysql_query("INSERT INTO customer_order(
id,quantity,item_id,
total_price,shipping_address,
shipping_date,customer_id)
VALUES ('','$quantity','$item_id','$total_price',
'','',
'$lastId')") or die (mysql_error());
}
}
}