SimpleshoPHP

Detailed Analysis - Part 4.5

rmfmbag.php

Whoops! Almost left this out. It's the flip side of addtobag. The customer is always right, and one thing that the customer has to be able to do is put something back.

Like addtobag, this "page" does not display any HTML on the visitor's browser. All it does is update the database.

Here's the rmfmbag code. Let's skip the narrative this time; it's much the same as on the addtobag page.


<?
require_once("startme.inc");
if (! isset($_SESSION["xvalid"])) {
        header("Location: main.php");
        exit;
}

if (!($sku)) {
        header("Location: main.php");
        exit;
}

<!-- Take the item out of the "bag" table for this session;
 but how many?  Have to get $qty from the bag first   -->
$cua = "select qty from bag where sess = '$PHPSESSID' and sku='$sku'";
$cua_result =  mysql_query($cua,$connection)
        or die ("Couldn't get count from bag");
$row = mysql_fetch_array($cua_result);
$qty = $row["qty"];

$rm = "delete from bag where sess = '$PHPSESSID' and sku='$sku'";
$rm_result = mysql_query($rm,$connect)
        or die ("Couldn't remove item from bag");

<!-- Put it back on the shelf -->

$stoc = "update books set stock = stock + $qty where sku='$sku'";
$stoc_result = mysql_query($stoc,$connect)
	or die ("Couldn't update inventory");

$item_count_total = $item_count_total - $qty;

<!-- Return the customer to the (updated) bookbag  -->
header("Location: bookbag.php");
exit;
?>

Next... bookbag.php!


The Technical Walkthrough

Summary

Detailed descriptions

SimpleshoPHP Home


You are invited to post comments or questions on the SimpleshoPHP forum at SourceForge.net.

SourceForge.net Logo


Copyright 2003-2005, Kevin Martin, dba Brass Cannon Consulting.
The project "SimpleshoPHP" is Free Software, distributed
under the LGPL as described at opensource.org