...

View Full Version : Unable to delete items in shopping cart



jonno4885
08-19-2011, 04:49 AM
Hi guys I am a bit lost with this. I have created this shopping cart script:




<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
echo "Your Shooping cart contains the following:";
if(isset($_POST['submit']))
{
$itemname = $_POST['h1'];

//echo $_SESSION['itemname'][$itemname];
unset($_SESSION['itemqty'][$itemname]);
unset($_SESSION['itemprice'][$itemname]);
unset($_SESSION['itemname'][$itemname]);
}

echo "<br/><br/>";
echo "<table border='1'>";
echo "<tr><th>Name</th><th>Quantity</th><th>Price</th></tr>";
foreach($_SESSION['itemname'] as $key=>$value)
{

echo
'<tr><td>'.$_SESSION['itemname'][$key].'</td><td><input
type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td><td>'.$_SESSION['itemprice'][$key].'</td><td>
<form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete">
<input type="hidden" name="h1" value='.$key.'></td></tr>';

}




echo "</table>";

?>
</body>
</html>




I however cannot delete items from the cart when viewing the cart. Any pointers?

Fumigator
08-19-2011, 03:26 PM
As a general rule you should never name a submit button "submit". It causes problems. Name it "sub_btn" or "submit_button", but not "submit".

This may or may not solve your problem.

Did you verify (with an echo statement) your "if" condition is evaluating "true"?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum