PHP Cookie:从购物车中删除商品

时间:2014-01-19 13:14:32

标签: php cookies

我想通过使用cookie向用户显示项目,我遇到了一个问题,当想要从列表中删除单个cookie时没有任何反应。对于显示给用户的每条记录,都会有一个删除按钮。目前,当单击删除按钮时,cookie值不会设置为空值。对于初始测试,唯一将设置为空白的cookie是cookievalue1

if (isset($_REQUEST['attempt']))    {

if (isset($_POST['sound1']))    {
    $intwoMonth = 60 * 60 * 24 * 60 + time();
    setcookie("cookievalue1","",$intwoMonth);
}

}


$i = 1;
$x = 4;

$username = "Username";
$orderno = "0353627";
$item1 = "Bread";
$price1 = "$50";
$item2 = "Cheese";
$price2 = "$46";
$subtotal = "$96";
$tax = "5%";
$total = "$100";
$var = NULL;

$cookiearray = array($username,$orderno,$item1,$price1,$item2,$price2,$subtotal,$tax,$total);   
print_r($cookiearray);  print '<br></br>';  print '<br></br>';

while ($i < $x) {   


 $cookiearray1 = serialize($cookiearray);

 setcookie("cookievalue" . $i, $cookiearray1, time()+3600);
 print '<br></br>';

 $var = unserialize($cookiearray1);


 $var2 = unserialize($cook1);
 print $var2[$i];
 print '<br></br>';print '<br></br>';

print '
<body>
<form action="cookieandarray6.php?attempt" method="post"/>
<input type="delete" name="sound1" value="sound1"<br><br>
<input type="submit" value="Delete"/>
</form>
</body>';

print '<br></br>';print '<br></br>';
$i = $i + 1;
}




?>

0 个答案:

没有答案