13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Solution Overview<br />

821<br />

Listing 33.3<br />

Continued<br />

}<br />

}<br />

$$e = trim($$e);<br />

// default values for global variables<br />

if($mode=='') {<br />

$mode = 'Books'; // No other modes have been tested<br />

}<br />

if($browseNode=='') {<br />

$browseNode = 53; //53 is bestselling non-fiction books<br />

}<br />

if($page=='') {<br />

$page = 1; // First Page - there are 10 items per page<br />

}<br />

//validate/strip input<br />

if(!eregi('^[A-Z0-9]+$', $ASIN)) {<br />

// ASINS must be alpha-numeric<br />

$ASIN ='';<br />

}<br />

if(!eregi('^[a-z]+$', $mode)) {<br />

// mode must be alphabetic<br />

$mode = 'Books';<br />

}<br />

$page=intval($page); // pages <strong>and</strong> browseNodes must be integers<br />

$browseNode = intval($browseNode);<br />

// it may cause some confusion, but we are stripping characters out from<br />

// $search it seems only fair to modify it now so it will be displayed<br />

// in the heading<br />

$search = safeString($search);<br />

if(!isset($_SESSION['cart'])) {<br />

session_register('cart');<br />

$_SESSION['cart'] = array();<br />

}<br />

// tasks that need to be done before the top bar is shown<br />

if($action == 'addtocart') {<br />

addToCart($_SESSION['cart'], $ASIN, $mode);<br />

}<br />

if($action == 'deletefromcart') {<br />

deleteFromCart($_SESSION['cart'], $ASIN);<br />

}<br />

if($action == 'emptycart') {<br />

$_SESSION['cart'] = array();

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!