spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / carts / chap7 / 2 To page 1To page 2To page 3To page 4current pageTo page 6To page 7To page 8
[previous] [next]

Usable Shopping Carts, Chapter 7: CC Validation and Verification

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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 To page 1To page 2To page 3To page 4current pageTo page 6To page 7To page 8
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: December 26, 2002
Revised: December 26, 2002

URL: http://webreference.com/programming/carts/chap7/2/5.html