Jump to content

Shopping cart


spearchilduser

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.