我正在尝试编程简单添加购物车,更新购物车和删除购物车但我在删除特定会话时遇到问题 为此,当我尝试删除一个项目,它删除所有项目,但我只想要一个项目像亚马逊所以我将感谢任何帮助^ _ ^"
码
<?php
session_start();
$test=$_POST['test'];
if(isset($_POST['submit'])){
$count=count($_SESSION['shopping_cart']);
$_SESSION['shopping_cart'][$count]['id1']= $count;
$id222= $_SESSION['shopping_cart'][$count]['id']=$test ;
$_SESSION['shopping_cart'][$count]['name']= $_POST['name'] ;
$_SESSION['shopping_cart'][$count]['price']= $_POST['price'] ;
echo " done";
}
// for update
if(isset($_POST['update1'])) {
$id22=$_POST['update'];
foreach($id22 as $id12 => $test1) {
$_SESSION['shopping_cart'][$id12]['id']=$test1 ;
echo $id12 ;
echo " $test1 <br> ";
}
}
// for delete
if(isset($_POST['delete'])) {
$id221=$_POST['update'];
foreach($_SESSION['shopping_cart'] as $id12 => $test1) {
if($id22 == $id_product ){
unset($_SESSION['shopping_cart'][$id12] ) ;
}
}
}
$total=0;
foreach($_SESSION['shopping_cart'] as $product){
$id_product= $product['id1'];
echo " <form action='' method='POST' ><input type='text' name='update[$id_product]' value= '$product[id]' >
<input name='delete' type='submit' value='delete' >
";
echo " <input name='delete' type='submit' value='delete' >";
echo " name = $product[name] <br> ";
$total= $total + ($product[id]) * ($product[price]) ;
}
echo $total ;
echo " <input name='update1' type='submit' value='update' > </form>";
echo $count;
?>
<form action="" method="post" >
<select name="test">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="11">11</option>
<option value="12">21</option>
<option value="13">31</option>
</select>
<input name="name" type="text" >
<input name="price" placeholder="price" type="text" >
<input type="submit" name="submit" value="add">
</form>
&#13;