它没有进入if( $_SERVER['REQUEST_METHOD']=='POST')
所以我试过了
$_SERVER['REQUEST_METHOD']='POST'
仍显示错误
注意:C:\ Abyss Web Server \ htdocs \ new 1.php中的未定义索引:qty 第9行
警告:在C:\ Abyss Web中为foreach()提供的参数无效 第9行的Server \ htdocs \ new 1.php
注意:第22行的C:\ Abyss Web Server \ htdocs \ new 1.php中的数组到字符串转换
session_start();
if(!isset($_SESSION['user_id'])){
require('login_tools.php');
load();
}
$_SERVER['REQUEST_METHOD']='POST';
if($_SERVER['REQUEST_METHOD']=='POST'){
foreach($_POST['qty'] as $item_id => $item_qty){
$id=(int)$item_id;
$qty=(int)$item_qty;
if($qty == 0){
unset($_SESSION['cart'][$id]);
}elseif($qty >0){
$_SESSION['cart'][$id]['quantity']=$qty;
}
}
$total=0;$e=array();
if(!empty($_SESSION['cart'])){
require('connectDB.php');
$q="SELECT * FROM shop WHERE item_id IN ";
foreach($_SESSION['cart'] as $id =>$value){
$q.=$id.',';
}
$q=substr($e,0,-1); " )ORDER BY item_id ASC";
$r=mysqli_query($dbc,$q);
}else{
$err[]="your cart is currently empty";
}
}
?>