购物车数量 PHP


cart quantity php

我在更新购物车中的产品时遇到错误。

注意:数组到字符串的转换在 C:''xampp''htdocs''ecommerce''cart.php109

第 109 行在下面的代码中引用了包含this['qty']输入类型数量的输入。

<?php
function updatecart(){
global $con;
$ip=getIp(); 
if(isset($_POST['update_cart'])){
foreach($_POST['remove'] as $remove_id){
$delete_product="delete from cart where p_id='$remove_id' AND ip_add='$ip'";
$run_delete = mysqli_query($con, $delete_product);
if($run_delete){   
  echo "<script>window.open('cart.php','_self')</script>";
    }
}
}
} if(isset($_POST['continue'])){
echo "<script>window.open('index.php','_self')</script>";
}

>$remove_id返回的是数组而不是字符串。

您需要var_dump($remove_id)才能查看返回数据的格式。

从那里您将能够识别内部数组的键。

所以你会传递$remove_id[key]。

您还应该考虑保护您的查询,如注释中所述,它容易受到 SQL 注入的影响。看看这个 如何防止 PHP 中的 SQL 注入?