I'm having some problems with a shopping cart array that will hold the items and struggling to get it to work as I want.
It's for a photography site to sell photos in a variety of size prints. I have the photo details stored in one table with the sizes and prices in a separate table.
On the individual photo page I have an add to cart button, which sends the photo id, size and price to a new page.
I've been trying to get the details into an array with some success but it's not working quite like I want and I can't iterate the details into a table as I want to either.
A session is set up for the cart as $_SESSION['cart']. A session is also set up to store the total quantities as $_SESSION['qty'].
Here's my code so far:
Code: Select all
if (isset($_GET['new']))
{
$photo_id = $_POST['id'];
$photo_size = $_POST['size'];
$price = $_POST['price'];
if (isset($_SESSION['cart']))
{
$items = array($_SESSION['cart']);
}
else
{
$items = array();
}
if (isset($_SESSION['qty']))
{
$item_qty = $_SESSION['qty'];
}
else
{
$item_qty = 0;
}
array_push($items, $photo_id, $photo_size, $price);
$_SESSION['cart'] = $items;
$_SESSION['qty'] = ++$item_qty;
header("Location: view_cart.php?cart");