Specifications
if (!$result)
return false;
}
$query = “select customerid from customers where
name = ‘$name’ and address = ‘$address’
and city = ‘$city’ and state = ‘$state’
and zip = ‘$zip’ and country = ‘$country’”;
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$customerid = mysql_result($result, 0, “customerid”);
else
return false;
$date = date(“Y-m-d”);
$query = “insert into orders values
(‘’, $customerid, $total_price, ‘$date’, ‘PARTIAL’, ‘$ship_name’,
‘$ship_address’,’$ship_city’,’$ship_state’,’$ship_zip’,
‘$ship_country’)”;
$result = mysql_query($query);
if (!$result)
return false;
$query = “select orderid from orders where
customerid = $customerid and
amount > $total_price-.001 and
amount < $total_price+.001 and
date = ‘$date’ and
order_status = ‘PARTIAL’ and
ship_name = ‘$ship_name’ and
ship_address = ‘$ship_address’ and
ship_city = ‘$ship_city’ and
ship_state = ‘$ship_state’ and
ship_zip = ‘$ship_zip’ and
ship_country = ‘$ship_country’”;
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$orderid = mysql_result($result, 0, “orderid”);
else
return false;
// insert each book
foreach($cart as $isbn => $quantity)
{
$detail = get_book_details($isbn);
Building a Shopping Cart
C
HAPTER 25
25
B
UILDING A
SHOPPING CART
571
LISTING 25.15 Continued
31 7842 CH25 3/6/01 3:39 PM Page 571










