removeAll(); $_SESSION['cart'] = serialize($cart); header('Location: shop.php'); end(); } // item parameter indicates an attempt to add or remove items if (isset($_GET['item'])) { // verify item is valid $query = sprintf('SELECT ITEM_ID FROM %sSHOP_INVENTORY WHERE ' . 'ITEM_ID = %d', DB_TBL_PREFIX, $_GET['item']); $result = mysql_query($query, $GLOBALS['DB']); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $item = $row['ITEM_ID']; // add item to cart if (isset($_GET['add'])) { $cart->addItem($item); } // remove item from cart else if (isset($_GET['remove'])) { $cart->removeItem($item); } } mysql_free_result($result); // save cart to session and redirect to the previously viewed page $_SESSION['cart'] = serialize($cart); header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER'])); exit(); } // view shopping cart's contents else { // update item quantities in shopping cart if (isset($_GET['update'])) { foreach ($_POST['qty'] as $item => $qty) { $cart->addItem($item, $qty); } } ob_start(); echo '
Back to all categories'; // verify category parameter and construct suitable back link if passed if (isset($_GET['category'])) { $query = sprintf('SELECT CATEGORY_ID, CATEGORY_NAME FROM ' . '%sSHOP_CATEGORY WHERE CATEGORY_ID = %d', DB_TBL_PREFIX, $_GET['category']); $result = mysql_query($query, $GLOBALS['DB']); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo ' / Back to ' . $row['CATEGORY_NAME'] . ''; } mysql_free_result($result); } echo '
'; if ($cart->isEmpty) { echo 'Your cart is empty.
'; } else { // display empty cart link echo ''; // encapsulate list in form so quantities may be changed echo '