Specifications

(We covered variable variables in Chapter 1, PHP Crash Course.) As a reminder, when we
refer to $$isbn, we are actually referring to the variable whose name is stored in $isbn. These
are the form fields from the Save Changes form.
If any of the fields were set to zero, we remove that item from the shopping cart altogether,
using unset(). Otherwise, we update the cart to match the form fields, as follows:
if($$isbn==”0”)
unset($cart[$isbn]);
else
$cart[$isbn] = $$isbn
After these updates, we again use calculate_price() and calculate_items() to work out
the new values of the
$total_price and $items session variables.
Printing a Header Bar Summary
You will have noticed that in the header bar of each of the pages in the site, a summary of
whats in the shopping cart is presented. This is obtained by printing out the values of the ses-
sion variables $total_price and $items. This is done in the do_html_header() function.
These variables are registered when the user first visits the show_cart.php page. We also need
some logic to deal with the cases where a user has not yet visited that page. This logic is also
in the do_html_header() function:
if(!$items) $items = “0”;
if(!$total_price) $total_price = “0.00”;
Checking Out
When the user clicks the Go to Checkout button from the shopping cart, this will activate the
checkout.php script. The checkout page and the pages behind it should be accessed via SSL,
but the sample application does not force you to do this. (To read more about SSL, review
Chapter 15, Implementing Secure Transactions with PHP and MySQL.)
The checkout page is shown in Figure 25.8.
This script requires the customer to enter her address (and shipping address if it is different). It
is quite a simple script, which you can see by looking at the code in Listing 25.13.
Building Practical PHP and MySQL Projects
P
ART V
566
31 7842 CH25 3/6/01 3:39 PM Page 566