Credit Card Display Forms in PHP/MySQL--Part 2 of Chapter 7 from Usable Shopping Carts (2/8)
[previous] [next] |
Usable Shopping Carts, Chapter 7: CC Validation and Verification
This next part should look familiar as it's almost identical to the first portion of the code we used in Step 2 to include the error-checking routines for validation:
<?php
$err_msg = "<p class=\"error\">There were problems
with the following fields:</p>\n<p>";
require_once "../includes/validate.inc";
$valid = TRUE;
if( isset($HTTP_POST_VARS["$cc_submit"]) )
{
$cc_submit = $HTTP_POST_VARS["$cc_submit"];
$valid = validate();
}
if( $err_msg !=
"<p class=\"error\">There were problems with the following fields:</p>\n<p>" )
{
echo "<table border=\"2\" bordercolor=\"#CC0033\"
bgcolor=\"#FFFEE\" cellpadding=\"2\">\n<tr><td>";
echo $err_msg;
echo "</td></tr>\n</table>\n";
}
if( isset($cc_submit) && $valid )
{
Once the form is validated, we're ready to process the order. First, we retrieve some values that were passed from the previous page via POST:
$ship_type = $HTTP_POST_VARS["ship_type"];
$order_total = $HTTP_POST_VARS["order_total"];
We're still using the variable $s_id
to hold the value of the session ID, but now we'll maintain it between page
loads by storing it as the value of a hidden form field and retrieving it
from $HTTP_POST_VARS:
$s_id = $HTTP_POST_VARS["s_id"];
Then we create a new record in the orders table. It's assumed that only records relating to paid orders are stored here:
$o_query = "INSERT INTO orders
(session_id,shipping_type_id,order_total,order_datetime) ";
$o_query .= "VALUES ('$s_id','$ship_type','$order_total',NOW())";
$o_result = mysql_query($o_query)
or die("<p>There was a problem in processing your order. Please contact
us by email or phone for further assistance. Please be ready to supply
your reference code, which is <b>$s_id</b>, so that we can
retrieve your ordering information.</p>");
[previous] [next] |
Created: December 26, 2002
Revised: December 26, 2002
URL: http://webreference.com/programming/carts/chap7/2/2.html

Find a programming school near you