Hello, So I managed to do the AddToCart function and stuff but I dont know how to display the cart
this is the add to cart function
<?php
session_start();
// get the product id
$DVDID = isset($_GET['DVDID']) ? $_GET['DVDID'] : "";
$name = isset($_GET['NameOfTheDVD']) ? $_GET['NameOfTheDVD'] : "";
/*
* check if the 'cart' session array was created
* if it is NOT, create the 'cart' session array
. */
if(!isset($_SESSION['cart'])){
$_SESSION['cart'] = array();
}
// check if the item is in the array, if it is, do not add
if(in_array($DVDID, $_SESSION['cart'])){
// redirect to product list and tell the user it was added to cart
header('Location: shop.php?action=exists&id' . $DVDID . '&name=' . $name);
}
// else, add the item to the array
else{
array_push($_SESSION['cart'], $DVDID);
// redirect to product list and tell the user it was added to cart
header('Location: shop.php?action=add&id' . $DVDID . '&name=' . $name);
}
?>
this is the basket where the items should be displayed
<?php
$action = isset($_GET['action']) ? $_GET['action'] : "";
$Quantity = isset($_GET['Quantity']) ? $_GET['Quantity'] : "";
$DVDID = isset($_GET['DVDID']) ? $_GET['DVDID'] : "";
$name = isset($_GET['NameOfTheDVD']) ? $_GET['NameOfTheDVD'] : "";
if($action=='removed'){
echo "<div>" . $_GET['NameOfTheDVD'] . " was removed from cart.</div>";
}
if (!isset($_SESSION["cart"]) || count($_SESSION["cart"]) < 1) {
echo 'cart if emepy';
} else {
if(isset($_SESSION['cart'])){
$ids = "";
foreach($_SESSION['cart'] as $DVDID){
$ids = $ids . $DVDID . ",";
}
$ids = rtrim($ids, ',');
require "connect.php";
$query = "SELECT `DVDID`, `NameOfTheDVD`, `Quantity` FROM `DVD` WHERE DVDID IN ({$ids})";
$stmt = $dbhandle->prepare( $query );
$stmt->execute();
var_dump($_SESSION['cart']);
$num = $stmt->rowCount();
$totalQuantity = 0;
if($num>0){
echo "<table border='0'>";//start table
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>DVD NAME</th>";
echo "<th>Quantity</th>";
echo "<th>Action</th>";
echo "</tr>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$totalQuantity += $Quantity;
//creating new table row per record
echo "<tr>";
echo "<td>" . $row['DVDID'] . "</td>";
echo "<td>" . $row['NameOfTheDVD'] . "</td>";
echo "<td class='textAlignCenter'>";
echo "<a href='RemoveFromCart.php?id={$DVDID}&name={$name}' class='customButton'>";//not working
echo "<img src='remove-from-cart.png' title='Remove from cart' />";
echo "</a>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<th class='textAlignCenter'>Total Quantity</th>";
echo "<th class='textAlignRight'>{$totalQuantity}</th>";
echo "<th></th>";
echo "</tr>";
echo "</table>";
echo "<br/><div><a href='#' class='customButton'>Checkout</a></div>";
}else{
echo "<div>No products found in your cart.</div>";
}
}else{
echo "<div>No products in cart yet.</div>";
}
?>
Any help would be appriciated thanks