当单击更新按钮时,它不会同时更新数量,而只会更新价格中的价格,它显示致命错误:未捕获错误:不支持的操作数类型在线上将数量和price_value相乘。谢谢你
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
<input type="hidden" name="size_id[]" value="<?php echo $size_id_2; ?>">
<input name="quantity[]" value="<?php echo $quantity; ?>" type="number" id="number" >
<input type="hidden" name="price[]" value="<?php echo $price; ?>">
<?php
if (isset($_POST['update'])) {
$product_id = $_POST['product_id'];
$size_id = $_POST['size_id'];
$quantity = $_POST['quantity'];
$price_value = $_POST['price'];
$updated_price = $price_value * $quantity;
foreach($product_id as $index => $h){
$v = $size_id[$index];
$q = $quantity[$index];
$p = $updated_price[$index];
$update_query = "UPDATE cart SET product_price='$p',quantity='$q' WHERE product_id='$h' AND size_id='$v'";
$run_query = mysqli_query($con , $update_query);
if($run_query){
echo"<script>window.open('cart.php','_self')</script>";
}
}
}
?>
<button type="submit" name="update" class="btn btn-icon btn-icon-left btn-primary btn-shape-circle offset-top-35"><i class="fa fa-wrench"></i> Update Cart</button>
</form>
答案 0 :(得分:0)
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>">
<input type="hidden" name="size_id[]" value="<?php echo $size_id_2; ?>">
<input name="quantity[]" value="<?php echo $quantity; ?>" type="number" id="number" >
<input type="hidden" name="price[]" value="<?php echo $price; ?>">
<?php
if (isset($_POST['update'])) {
$product_id = $_POST['product_id'];
$size_id = $_POST['size_id'];
$quantity = $_POST['quantity'];
$price_value = $_POST['price'];
$total_price = array($price_value);
$values_multiple = array_sum($total_price);
foreach($product_id as $index => $h){
$v = $size_id[$index];
$q = $quantity[$index];
$p = $price_value[$index];
$values_multiple = $q * $p;
$total_grand = $values_multiple;
$update_query = "UPDATE cart SET product_price='$total_grand',quantity='$q' WHERE product_id='$h' AND size_id='$v'";
$run_query = mysqli_query($con , $update_query);
if($run_query){
echo"<script>window.open('cart.php','_self')</script>";
}
}
}
?>