Specifications

The logic here is straightforward: We check that the user filled out the form and inserted
details into the database using a function called insert_order(). This is a simple function that
pops the customer details into the database. The code for it is shown in Listing 25.15.
LISTING 25.15 insert_order() Function from order_fns.phpThis Function Inserts All the
Details of the Customers Order into the Database
function insert_order($order_details)
{
global $total_price;
global $cart;
//extract order_details out as variables
extract($order_details);
//set shipping address same as address
if(!$ship_name&&!$ship_address&&!$ship_city&&
!$ship_state&&!$ship_ zip&&!$ship_
country)
{
$ship_name = $name;
$ship_address = $address;
$ship_city = $city;
$ship_state = $state;
$ship_zip = $zip;
$ship_country = $country;
}
$conn = db_connect();
//insert customer address
$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)
{
$customer_id = mysql_result($result, 0, “customerid”);
}
else
{
$query = “insert into customers values
(‘’, ‘$name’,’$address’,’$city’,’$state’,’$zip’,’$country’)”;
$result = mysql_query($query);
Building Practical PHP and MySQL Projects
P
ART V
570
31 7842 CH25 3/6/01 3:39 PM Page 570