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
https://forums.phpfreaks.com/topic/255225-shopping-cart/#findComment-1308569
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
https://forums.phpfreaks.com/topic/255225-shopping-cart/#findComment-1308572
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.