我有三个变量($product_id、$size_id、$quantity),它们从“form”中获取并插入到 pending_order 表中。所以我使用了 array_combine 函数来组合三个变量,而不是使用每个循环来插入多条记录。但它显示一个错误
“警告:array_combine() 需要 2 个参数,3 个给定”。
所以我完全被卡住了,有没有其他方法可以在数组中传递这三个变量,而不是用于每个循环来插入记录。
<form method="post" action="">
<input type="hidden" name="ip_address" value="<?php echo $ip_address; ?>">
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
<input type="hidden" name="size_id[]" value="<?php echo $size_id; ?>">
<input type="hidden" name="quantity[]" value="<?php echo $quantity; ?>" >
<input type="submit" name="submit" value="Confirm Your Order">
</form>
<?php
if (isset($_POST['submit'])) {
$product_id = $_POST['product_id'];
$size_id = $_POST['size_id'];
$ip_address = $_POST['ip_address'];
$quantity = $_POST['quantity'];
$array = array_combine($product_id, $size_id, $quantity);
foreach ($array as $h => $v) {
$insert_pending = "INSERT INTO pending_orders
(cus_id,product_id,size_id,quantity,ip_address) VALUES
('$cus_id','$h','$v','$quantity','$ip_address')";
$run2 = mysqli_query($con, $insert_pending);
}
if($run2===true){
echo "<script>window.open('thanku.php','_self')</script>";
}else{
echo "<script>alert('Sorry, Try Again')</script>";
}
}