我有这个多维数组要插入到 mysql 数据库中:
{
customer_id: "25",
total: 238000,
firstname: "oci",
product: [
{
product_id: "6",
product_name: "Orange"
},
{
product_id: "5",
product_name: "Melon"
}
]
}
这是我的代码
$_POST = json_decode(file_get_contents('php://input'), true);
$customer_id= $_POST['customer_id'];
$total= $_POST['total'];
$firstname= $_POST['firstname'];
foreach ($_POST['product'] as $q_product => $v) {
$product_id = $v['product_id'];
$product_name= $v['product_name'];
$query = "INSERT INTO tbl_order
(order_id,customer_id,total,firstname) VALUES (NULL,'$customer_id','$total','$firstname')";
$queryy = "INSERT INTO tbl_order_product
(order_id,product_id,product_name) VALUES (LAST_INSERT_ID(),$product_id,'$product_name')";
}
$result = mysqli_query($link, $query);
$resultt = mysqli_query($link, $queryy);
我无法将“queryy”插入到 tbl_order_product,只能插入 tbl_order 表 请帮我将“product”数组插入到 tbl_order_product 表中。
Cats萌萌