I was trying to insert multiple items from my cart to my database(mysql). The code below processes only one row. Can you guys help me? What code should I use to execute multiple rows in one process? Thank you in advance.
if (isset($_POST['cart_btn'])) {
$product_id = $_POST['product_id'];
$product_name = $_POST['product_name'];
$filename = $_POST['filename'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$subtotal_item = $_POST['subtotal_item'];
$subtotal = $_POST['subtotal'];
$total = $_POST['total'];
$shipping_fee = $_POST['shipping_fee'];
if (!isset($errormessage)) {
$order_id = time().'-'.mt_rand();
$stmt = $db->prepare('INSERT INTO cart(order_id,product_id,product_name,filename,price,quantity,subtotal_item,subtotal,total,shipping_fee) VALUES(:uorder_id,:uproduct_id,:uproduct_name,:ufilename,:uprice,:uquantity,:usubtotal_item,:usubtotal,:utotal,:ushipping_fee)');
$stmt->bindParam(':uorder_id', $order_id);
$stmt->bindParam(':uproduct_id', $product_id);
$stmt->bindParam(':uproduct_name', $product_name);
$stmt->bindParam(':ufilename', $filename);
$stmt->bindParam(':uprice', $price);
$stmt->bindParam(':uquantity', $quantity);
$stmt->bindParam(':usubtotal_item', $subtotal_item);
$stmt->bindParam(':usubtotal', $subtotal);
$stmt->bindParam(':utotal', $total);
$stmt->bindParam(':ushipping_fee', $shipping_fee);
if ($stmt->execute()) {
$successmessage = "Please wait, processing your order...";
header("refresh:5;checkout.php");
} else {
$errormessage = "process on error....";
}
}
}