<?php ob_start(); if ($_SERVER['REQUEST_METHOD'] == "GET" and isset($_GET['id'])) { addToBasket(); getBasket(); header("Location:{$_SERVER['HTTP_REFERER']}"); exit; } //--------------------------------------------------------------------------------------------------- function addToBasket() { $item_id = abs((int) $_GET['id']); $customer_id = $_COOKIE['PHPSESSID']; $link = new mysqli("127.0.0.1", "root", "", "eShop"); if ($_SERVER['REQUEST_METHOD'] == "GET") { $query = "INSERT INTO `basket`(`customer_id`,`item_id`,`item_quantity`)\n\t\t\t\t\tVALUES (\"{$customer_id}\", {$item_id}, 1);"; $link->query($query) or die(mysqli_error($link)); $link->close(); } } function getBasket() { $customer_id = $_COOKIE['PHPSESSID']; $link = new mysqli("127.0.0.1", "root", "", "eShop"); $query = "SELECT `id`, `customer_id`, `item_id`, `item_quantity` FROM `basket`\n\t\t\t\tWHERE `customer_id` = \"{$customer_id}\";"; $result = $link->query($query) or die(mysqli_error($link)); echo "Now in your basket {$result->num_rows} items"; $link->close(); } function itemList()
<?php require 'basket.func.php'; echo getBasket();
} if (isset($_POST["prID"]) && isset($_POST["aPrice"]) && isset($_POST["EmpNum"])) { $res = addBasket($_POST); } if (isset($_POST["submit"])) { if (empty($_POST["title"]) || empty($_POST["point"]) || empty($_POST["Delivery"]) || empty($_POST["content"]) || empty($_FILES)) { $error_message = "<div class='error'>Please fill in all fields</div>"; } else { $file_path = insertFile($_FILES, $_POST["menu_id"], $_POST["sub_id"]); if ($file_path != 'error') { $data = array('aTitle' => $_POST["title"], 'aPrice' => $_POST["point"], 'delivery' => $_POST["Delivery"], 'aContent' => $_POST["content"], 'menuID' => $_POST["menu_id"], 'subID' => $_POST["sub_id"], 'Image_name' => $file_path); insertProduct($data); } } } $basket = getBasket($_SESSION["user"]->EmpNum); if (count($basket) > 0 && is_array($basket)) { $basket_isset = true; } else { $basket_isset = false; } if (isset($_GET["menu_id"])) { $menu_id = $_GET["menu_id"]; $menu = getMenuRows($menu_id); } if (isset($_GET['prID'])) { $product = getProductByID($_GET['prID']); $sub = getMenuSub($product["subID"]); } $val = $_SESSION['user']->administrator; ?>