| home / programming / carts / chap7 / 2 | [previous] [next] |
|
|
Now we can notify the user that the order's been processed (at least so far as the onsite database in concerned).
<h2>Thank You!</h2><p>You order in the amount of $<?php printf("%.2f",$order_total); ?> has been processed.</p>
<?php
While we're at it, let's also send the customer a confirming e-mail.
|
We get the customer's e-mail address and name from the customers table and assign their
values to the variable $to and $name;
and we assign a suitable subject line string to the variable $subject as well.
$c_query = "SELECT customer_first_name,customer_last_name,
customer_email ";
$c_query .= "FROM customers WHERE session_id=$s_id";
$c_result = mysql_query($c_query);
$c_row = mysql_fetch_assoc($c_result);
$to = $c_row["customer_email"];
$name = $c_row["customer_first_name"] . " " .
$c_row["customer_last_name"];
$subject = "TuneIn! Order Confirmation";
We'll store the body of the e-mail in a variable named $message,
which we'll build up as we go along, beginning with an appropriate greeting:
$message = "Dear $name,\n\nYour order for\n\n";
What follows is essentially the same code that we used to generate the Cart
Detail display for the page cart.php.
The only substantial difference is that we're generating plain text rather
than HTML, so we do our formatting with ASCII linebreak and tab characters
(\n and \t).
$a_query = "SELECT c.cart_id,c.quantity,pg.product_group_title,
f.format_description,pc.product_code_price ";
$a_query .= "* CASE WHEN ISNULL(s.special_percentage) OR
s.start_date>CURDATE() OR s.end_date<CURDATE() ";
$a_query .= "THEN 1 ELSE (100-s.special_percentage)*.01 END
AS price FROM product_codes pc ";
$a_query .= "LEFT JOIN product_groups pg USING (product_group_id) ";
$a_query .= "LEFT JOIN formats f ON f.format_id=pc.format_id ";
$a_query .= "LEFT JOIN carts c
ON pc.product_code_id=c.product_code_or_event_id ";
$a_query .= "LEFT JOIN specials s
ON pc.product_code_id=s.product_group_or_event_id ";
$a_query .= "WHERE c.session_id='$s_id' AND c.item_type_id=1";
$a_result = mysql_query($a_query);
$album_total = 0;
if(mysql_num_rows($a_result) > 0)
{
while($a_row = mysql_fetch_assoc($a_result))
{
$c_id = $a_row["cart_id"];
$quantity = $a_row["quantity"];
$price = $a_row["price"];
$code = $a_row["product_or_event_code"];
$title = $a_row["product_group_title"];
$format = $a_row["format_description"];
$item_amount = $quantity * $price;
$album_total += $item_amount;
$message .= "($quantity)\t$format -- $title @ \$";
$message .= sprintf("%.2f", $price) . "--> \t\$"
. sprintf("%.2f", $item_amount);
The sprintf()
function works to format output in a similar fashion to printf(), and takes
the same sorts of arguments. The only difference is that sprintf() returns
a string instead of outputting it immediately.
$message .= "\n";
}
}
$message .= "\n\n";
$ticket_total = 0;
// ticket detail -- similar to that used for cart.php...
$t_query = "SELECT c.cart_id,c.quantity,e.event_name,
e.event_datetime,e.event_price ";
$t_query .= "* CASE WHEN ISNULL(s.special_percentage)
OR s.start_date>CURDATE() OR s.end_date<CURDATE() ";
$t_query .= "THEN 1 ELSE (100-s.special_percentage)*.01 END
AS price,v.venue_city,st.state_code ";
$t_query .= "FROM events e LEFT JOIN venues v USING (venue_id) ";
$t_query .= "LEFT JOIN states st USING (state_id) ";
$t_query .= "LEFT JOIN tunein.carts c
ON e.event_id=c.product_code_or_event_id ";
$t_query .= "LEFT JOIN tunein.specials s ON
e.event_id=s.product_group_or_event_id ";
$t_query .= "WHERE c.session_id='$s_id' AND c.item_type_id=2";
$t_result = mysql_query($t_query);
| home / programming / carts / chap7 / 2 | [previous] [next] |
Created: December 26, 2002
Revised: December 26, 2002
URL: http://webreference.com/programming/carts/chap7/2/4.html