I'm having this project for my school on doing a website for ordering of food and i'm stuck on doing the shopping cart code.
Firstly, i have manage to store my ordering into the session and now i'm stuck on doing the checking out of shopping cart.
can some one teach me how to store the session into the database ? so i can do a confirmation of the order i make ?
<?php
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['bento_id'];
} else {
$cart = $_GET['bento_id'];
$_SESSION['cart'] = $cart;
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['bento_id'] != $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')) {
$bento_id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($bento_id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$bento_id;
} else {
$newcart = $bento_id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?>
<?php
echo writeShoppingCart();
?>
<div id="contents">
<h1>Please check quantities...</h1>
<?php
echo showCart();
?>
<p><a href="viewmenu.php">Back to bento menu...</a></p>
<?php
}
else
{
echo "<p> </p>";
echo "<h4>Error: The page you tried to view can only be used when you're logged in.</h4>";
echo " ";
echo "<p> </p>";
echo "<a href='index.php'>Back to home</a>";
echo "<p> </p>";
}
?>
i hope some one can guide me. thanks :crying:


Sign In
Create Account

Back to top









