spearchilduser Posted January 17, 2012 Share Posted January 17, 2012 hi all i have a simple shopping cart up and runniing i just cannot think of how to remove all items within the cart i can do a remove one item easily but how woudl i remove all items inmy cart ? Would i delete the cookie id or ? Quote Link to comment https://forums.phpfreaks.com/topic/255225-shopping-cart/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2012 Share Posted January 17, 2012 Assuming that your cart data is stored as an array in a session variable named 'cart' - $_SESSION['cart'] = array(); // clear cart by making it an empty array For anything else, you would need to provide information about how your cart data is actually stored. Quote Link to comment https://forums.phpfreaks.com/topic/255225-shopping-cart/#findComment-1308569 Share on other sites More sharing options...
spearchilduser Posted January 17, 2012 Author Share Posted January 17, 2012 atm its not usign sessions code is below ?php switch($_GET["action"]) { case "add_item": { AddItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "update_item": { UpdateItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "remove_item": { RemoveItem($_GET["id"]); ShowCart(); break; } case "remove_all_item": { RemoveItem($_GET["id"]); ShowCart(); break; } default: { ShowCart(); } } To add remove etc on the cart function RemoveItem($itemId) { // Uses an SQL delete statement to remove an item from // the users cart global $dbServer, $dbUser, $dbPass, $dbName; // Get a connection to the database $conn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName); mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId"); } This is to remove a single item from the cart <a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a> This is the link set up to call the function to remove the item If this helps tHANKS Quote Link to comment https://forums.phpfreaks.com/topic/255225-shopping-cart/#findComment-1308572 Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2012 Share Posted January 17, 2012 mysql_query("delete from cart where cookieId = '" . GetCartId() . "'"); Quote Link to comment https://forums.phpfreaks.com/topic/255225-shopping-cart/#findComment-1308574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.