hi guys ive been stuck this this for a while..
now i have this
<?php echo "cartid is $cartId"; ?>
at the bottom of my webpage and this gives me a # that is the number i need to delete out of the cart table.
this code does nothing when i click the button. and im not sure why. can anyone see anything wrong with it?
the remove item function works sweet.
thanx in advance!
Chris
<?php
function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table
if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);
ShowCart($rs_cart);
break;
}
case "update_item":
{
UpdateItem($_GET["id"], $_GET["qty"]);
ShowCart($rs_cart);
break;
}
case "remove_item":
{
RemoveItem($_GET["id"]);
ShowCart($rs_cart);
break;
}
case "empty_cart":
{
EmptyCart($_GET["id"]);
ShowCart($rs_cart);
break;
}
default:
{
ShowCart($rs_cart);
}
}
?>
<?php
function RemoveItem($itemId)
{
// Uses an SQL delete statement to remove an item from
// the users cart
mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND itemId = $itemId");
}
function EmptyCart($itemId)
{
$query="DELETE * FROM cart WHERE cookieId = $cartId";
echo "query is $query<br />";
mysql_query($query);
}
?>
<html>
<form name="cart" action="">
<input type="submit" value="Reset" onclick="form.action='cart.php?action=empty_cart'" class="button" />
<input type="submit" value="Continue" onclick="form.action='details.php'" class="button" />
</form>
</html>