Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Include MySQL class
- require_once('inc/mysql.class.php');
- // Include database connection
- require_once('inc/global.inc.php');
- // Include functions
- require_once('inc/functions.inc.php');
- // Start the session
- session_start();
- // Process actions
- $cart = $_SESSION['beli'];
- $action = $_GET['action'];
- switch ($action)
- {
- case 'add':
- if ($cart)
- {
- $cart .= ',' . $_GET['idkek'];
- }
- else
- {
- $cart = $_GET['idkek'];
- }
- break;
- case 'delete':
- if ($cart)
- {
- $items = explode(',',$cart);
- $newcart = '';
- foreach ($items as $item)
- {
- if ($_GET['idkek'] != $item)
- {
- if ($newcart != '')
- {
- $newcart .= ',' . $item;
- }
- else
- {
- $newcart = $item;
- }
- }
- }
- $cart = $newcart;
- }
- break;
- case 'update':
- if ($cart)
- {
- $newcart = '';
- foreach ($_POST as $key=>$value)
- {
- if (stristr($key,'qty'))
- {
- $id = str_replace('qty','',$key);
- $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
- $newcart = '';
- foreach ($items as $item)
- {
- if ($id != $item)
- {
- if ($newcart != '')
- {
- $newcart .= ',' . $item;
- }
- else
- {
- $newcart = $item;
- }
- }
- }
- for ($i=1;$i<=$value;$i++)
- {
- if ($newcart != '')
- {
- $newcart .= ',' . $id;
- }
- else
- {
- $newcart = $id;
- }
- }
- }
- }
- }
- $cart = $newcart;
- break;
- }
- $_SESSION['beli'] = $cart;
- ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Senarai tempahan</title>
- <link rel="stylesheet" href="css/styles.css" />
- </head>
- <body>
- <div id="shoppingcart">
- <h1>Senarai Tempahan | <a href="../logout.php">Keluar...</a></h1>
- <?php
- echo writeShoppingCart();
- ?>
- </div>
- <div id="contents">
- <h1>Sila semak kuantiti...</h1>
- <?php
- echo showCart('lihat');
- ?>
- <p><a href="./">Kembali ke menu utama...</a></p>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment