if (isset($_SESSION['cart'])) {
        unset($_SESSION['cart']);
    }
    if (isset($_SESSION['total'])) {
        unset($_SESSION['total']);
    }
}
//cases for handling the cart
//and item is to be added
if (isset($_GET['add'])) {
    addToCart();
    unset($_GET['add']);
}
//the user has checked out
if (isset($_GET['checkedOut'])) {
    updateInventory();
    unset($_GET['checkedOut']);
}
//the cart has be cleared
if (isset($_GET['clear'])) {
    clearCart();
    unset($_GET['clear']);
}
?>

<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
	<title>Your Cart</title>
	<link rel="stylesheet" href="style.css">
	<link rel="stylesheet" href="ppageStyle.css">
Example #2
0
function placeOrder()
{
    // TODO: Do not die, display some useful links.
    $books = $_COOKIE['books'];
    if ($_SERVER['REQUEST_METHOD'] != 'POST' || empty($books)) {
        echo "<p class='center'>There is no order to place.</p>";
        return;
    }
    $connection = connect();
    if (!updateInventory($connection, $books)) {
        return;
    }
    $order_id = insertOrder($connection, $books);
    if (empty($order_id)) {
        return;
    }
    clearCart();
    // NOTE: this has to be called prior to any output.
    $payment_method = getPaymentMethodFromCardNumber($connection, $_POST['card_number']);
    $total_price_string = $_POST['total_price_string'];
    echo "\n      <p class='center'>Your credit card\n      <em><strong>{$payment_method}</strong></em>\n      is charged <em><strong>\${$total_price_string}</strong></em>.</p>\n      <p class='center'>\n      <a href='show_order.php?order_id={$order_id}'>\n      <em><strong>Order {$order_id}</strong></em></a>\n      is placed successfully.</p>";
    echo "<h2>Order Details</h2>";
    showOrderFromOrderId($connection, $order_id);
    mysql_close($connection);
}