| home / programming / carts / chap7 / 2 | [previous] [next] |
|
|
Of course, you should include some form of user-friendly error-handling for
each of the calls to mysql_query(). In cases where the failure of a
query doesn't critically impact the application for the user, you might want to use
something like the following code:
if( $t_result !== mysql_query($t_query) )
mail("tech_admin@tunein.site","Non-fatal DB Error",
"The query $t_query run on page $PHP_SELF for visitor $s_id failed.");
else
{
if( mysql_numrows($t_result) > 0 )
{
// ... etc. ...
}
}
It sends an e-mail automatically to someone in Technical Support and have the matter investigated.
if(mysql_num_rows($t_result) > 0)
{
while($t_row = mysql_fetch_assoc($t_result))
{
$c_id = $t_row["cart_id"];
$quantity = $t_row["quantity"];
$price = $t_row["price"];
$code = $t_row["event_id"];
$event = $t_row["event_name"];
$datetime = strtotime($t_row["event_datetime"]);
$date = date( "F jS", $datetime);
$time = date( "g:i A", $datetime);
$city = $t_row["venue_city"];
$item_amount = $quantity * $price;
$ticket_total += $item_amount;
$message .= "($quantity)\t$event -- $city, $date, $time @ \$";
$message .= sprintf("%.2f", $price) . "--> \t\$" .
sprintf("%.2f", $item_amount);
$message .= "\n";
}
}
We let the customer know the time and date on which the order was processed.
$currtime = date("g:i:s");
$currdate = date("l, j F, Y");
$message .= "\nwas processed at $currtime on $currdate.\n\n";
We also provide confirmation of the shipping method and the amount charged, as well as the total for merchandise and the total amount charged. We also include the session ID to use as a reference number.
$merch_total = $album_total + $ticket_total;
$shipping = $order_total - $merch_total;
$s_query = "SELECT shipping_type_description FROM shipping_types ";
$s_query .= "WHERE shipping_type_id = $ship_type";
$s_result = mysql_query($s_query);
$s_description = mysql_result($s_result,0);
$message .= "MERCHANDISE TOTAL: \$";
$message .= sprintf("%.2f",$merch_total) . "\n";
$message .= "SHIPPING ($s_description): \$";
$message .= sprintf("%.2f",$shipping) . "\n";
$message .= "ORDER TOTAL CHARGES: \$";
$message .= sprintf("%.2f",$order_total) . "\n";
$message .= "\n\nThank for your order. Your reference number is $s_id.\n";
To send the e-mail, we just call the PHP mail() function with $to,
$subject and $message as its arguments:
if( mail($to, $subject, $message) )
{
?>
You can include additional headers in the mail such as mimetype and
X-Sender. The sender field can also
be changed via the sendmail_from directive
in the php.ini file (on Windows).
We display a message to the customer indicating that the e-mail's been sent:
<p>You will be receiving a confirmation notice via email shortly.</p>
<p>Your order reference code is <?php echo $s_id; ?>.</p>
<?php
}
...unless, of course, something went wrong when we tried to send it:
else
{
?>
<p>Your order was processed but we had a problem in sending a confirmation
notice to you. Please contact us to verify your email address. Thanks!</p>
<?php
} // end if($cc_number && $valid)
| home / programming / carts / chap7 / 2 | [previous] [next] |
Created: December 26, 2002
Revised: December 26, 2002
URL: http://webreference.com/programming/carts/chap7/2/5.html