Php PDO:如何用一个进程在MySQL中插入多行

Php PDO:如何用一个进程在MySQL中插入多行,php,mysql,pdo,shopping-cart,multiple-records,Php,Mysql,Pdo,Shopping Cart,Multiple Records,我试图将多个项目从购物车插入数据库(mysql)。下面的代码只处理一行。你们能帮帮我吗?我应该使用什么代码在一个进程中执行多行?先谢谢你 if (isset($_POST['cart_btn'])) { $product_id = $_POST['product_id']; $product_name = $_POST['product_name']; $filename = $_POST['filename']; $price

我试图将多个项目从购物车插入数据库(mysql)。下面的代码只处理一行。你们能帮帮我吗?我应该使用什么代码在一个进程中执行多行?先谢谢你

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....";
        }
    }
}
值(…)、(…)、(…)…
或使用
while
do…while
for
foreach
等循环值,并在每次迭代时运行
INSERT
查询可能重复的