Accessing or Creating a Profile During Checkout

 

Introduction.  At this stage of our process the customer has chosen to select some items for their shopping basket and they have just pressed the button to check out.  The shopper has two main options to proceed.
  • Create a new profile
    • billing information
    • shipping information
    • credit card information
  • Access and existing profile
    • billing information
    • shipping information
    • credit card information

Unfortunately, for the developers, we need to make sure we can provide almost all of the same functionality we had in the profile related pages as a part of our checkout process.  We will do one major thing that is more restrictive by not allowing the shopper to update their profile during the checkout process unless they leave and come back to the checkout.

Fortunately, we will be able to make use of a lot of the same code we have already developed for our profile developments, we will mostly have to change the redirections between pages.

An image that represents the overall flow of the checkout process is given in the following.

 

 
The first page you need is called checkout_profile_access.php.  This is the page that the shopper is taken to when they press the Check Out button on the basket.php page.

 

<html>
<!-- profile_access.php - accessing a profile or creating a new profile during checkout -->
<head>
<title>Accessing or Starting a Profile</title>
</head>
<?php
include("includes/header.php");
?>

<p>&nbsp;</p>
<p>&nbsp;</p>
<div align="center">
<table border="0" cellpadding="3" cellspacing="0" align="center" width="650" id="layout_table">
<tr>
<td width="250" align="center"><b><font size="4" color="#999966">
Create a New Profile</font></b></td>
<td width="400" align="center"><b><font size="4" color="#999966">Access an
Existing Profile<br></font></b></td>
</tr>
<tr>
<td width="250">
<form method="POST" action="checkout_profile_new.php">
<div align="center">
<table border="0" cellpadding="3" cellspacing="0" align=center width="250" id="table_new">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Submit" name="cmd_new_profile" style="font-size: 14pt; font-weight: bold"></td>
</tr>
</table>
</div>
</form>
</td>
<td width="400">
<form method="POST" action="checkout_profile_access_validate.php">
<div align="center">
<table border="0" cellpadding="5" cellspacing="0" width="400" id="table_access">
<tr>
<td width="175" align=right><b><font size="4">E-Mail:</font></b></td>
<td width="225">
<input type="text" name="txt_original_email" size="30" style="font-size: 14pt"></td>
</tr>
<tr>
<td width="175" align="right"><b><font size="4">Password:</font></b></td>
<td width="225">
<input type="password" name="txt_original_password" size="12" style="font-size: 14pt"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit" name="cmd_access_rpofile" style="font-size: 14pt; font-weight: bold"></td>
</tr>
</table>
</div>
</form>
</td>
</tr>
<tr>
<td >&nbsp;</td>
<td align="center"><font color="#999966"><b>Forgotten your password,
<a href="email_password.php">click here</a>?</b></font></td>
</tr>
</table>
</div>
</body>
</html>

 

This page is primarily HTML that will result in the following form.

 

 

This creates what are hopefully two obvious options.
  • allows the shopper to create a new profile
  • allows the shopper to access an existing profile
    • it also allows for the shopper to have their password emailed to their email address

Since this is most like what we have already done in the past we will next develop the code for the shopper to create a new profile in checkout_profile_new.php.

 

<html>
<!-- profile_new.php - the form page for creating a new profile -->
<head><title>Adding Your Profile at Firefox</title></head>
<?php
include("includes/header.php");
include("includes/connection_config.php");
// initializing a blank error message
// this will be used to accumulate the input errors
// in order to feed them back to the user

$error_message = "";
// checking to make sure the form has actually been submitted
if ($submit_new_profile != "")
{

// if it has been submitted
// each of the form entries will be examined
// to see which have been omitted

if ($_REQUEST['txt_email'] == "")
{

$error_message = "$error_message<br>You have omitted your email address.";

}
else
{

// need to connect to the current data to make sure
// that the email address hasn't already been used

// connecting to the database on battcave.com
$link = mysql_connect($host, $user, $password);
// creating the query string
$query_string = "SELECT * FROM profile WHERE (email = '$txt_email')";
// executing the SQL statement
$result_set = mysql_db_query($db_name, $query_string, $link);
// if the resultset has any entries then you need to let the Shopper
// know the email address is already in use

while ($row = mysql_fetch_array($result_set))
{

$error_message = "$error_message<br><br>This email address is already in use.<br>";

}

mysql_close($link);

}
if ($_REQUEST['txt_password'] == "")
{

$error_message = "$error_message<br>You have omitted your password.";

}
if ($_REQUEST['txt_bill_first_name'] == "")
{

$error_message = "$error_message<br>You have omitted your billing first name.";

}
if ($_REQUEST['txt_bill_last_name'] == "")
{

$error_message = "$error_message<br>You have omitted your billing last name.";

}
if ($_REQUEST['txt_bill_address'] == "")
{

$error_message = "$error_message<br>You have omitted your billing address.";

}
if ($_REQUEST['txt_bill_city'] == "")
{

$error_message = "$error_message<br>You have omitted your billing city.";

}
if ($_REQUEST['sel_bill_state'] == "no_select")
{

$error_message = "$error_message<br>You have omitted your billing state.";

}
if ($_REQUEST['txt_bill_zip'] == "")
{

$error_message = "$error_message<br>You have omitted your billing zipcode.";

}
// this section checks for entries in the credit card information
if ($_REQUEST['txt_card_name'] == "")
{

$error_message = "$error_message<br>You have omitted the name on your credit card.";

}
if ($_REQUEST['sel_card_type'] == "no_select")
{

$error_message = "$error_message<br>You have omitted the your credit card type.";

}
if ($_REQUEST['txt_card_number'] == "")
{

$error_message = "$error_message<br>You have omitted your credit card number.";

}
// this section of code makes sure the expiration date
// is after today's date based on comparing the month and year

$month_number = date('m');
$year_number = date('Y');
// converting month names to numbers for comparison
if ($sel_card_month == "January") $sel_month_number = 1;
if ($sel_card_month == "February") $sel_month_number = 2;
if ($sel_card_month == "March") $sel_month_number = 3;
if ($sel_card_month == "April") $sel_month_number = 4;
if ($sel_card_month == "May") $sel_month_number = 5;
if ($sel_card_month == "June") $sel_month_number = 6;
if ($sel_card_month == "July") $sel_month_number = 7;
if ($sel_card_month == "August") $sel_month_number = 8;
if ($sel_card_month == "September") $sel_month_number = 9;
if ($sel_card_month == "October") $sel_month_number = 10;
if ($sel_card_month == "November") $sel_month_number = 11;
if ($sel_card_month == "December") $sel_month_number = 12;
// testing to see if the card's expiration month and year precede current month and year
if (($sel_card_year < $year_number) || (($sel_card_year == $year_number) && ($sel_month_number < $month_number)))
{

$error_message = "$error_message<br><br>Your card expiration date precedes today's date.<br>";

}

// checking to see if the user has checked
// the box so that shipping information is
// the same as billing

if ($chk_same_as != "")
{

$txt_ship_first_name = $txt_bill_first_name;
$txt_ship_last_name = $txt_bill_last_name;
$txt_ship_address = $txt_bill_address;
$txt_ship_city = $txt_bill_city;
$sel_ship_state = $sel_bill_state;
$txt_ship_zip = $txt_bill_zip;
$txt_ship_phone = $txt_bill_phone;
$txt_ship_fax = $txt_bill_fax;

}
else
{

if ($_REQUEST['txt_ship_first_name'] == "")
{

$error_message = "$error_message<br>You have omitted your shipping first name.";

}
if ($_REQUEST['txt_ship_last_name'] == "")
{

$error_message = "$error_message<br>You have omitted your shipping last name.";

}
if ($_REQUEST['txt_ship_address'] == "")
{

$error_message = "$error_message<br>You have omitted your shipping address.";

}
if ($_REQUEST['txt_ship_city'] == "")
{

$error_message = "$error_message<br>You have omitted your shipping city.";

}
if ($_REQUEST['sel_ship_state'] == "no_select")
{

$error_message = "$error_message<br>You have omitted your shipping state.";

}
if ($_REQUEST['txt_ship_zip'] == "")
{

$error_message = "$error_message<br>You have omitted your shipping zipcode.";

}

}
// displaying an error message on the page
// that gives the user appropriate feedback about what is missing

if ($error_message != "")
{

echo ("<br><center><font color=ff0000 size=4> $error_message </font></center>");

}
// if all the required inputs are present then
// we need to create the session_variables
// that will retain the inputs for use throughout the session
// and write these inputted values to our profile table

else
{

// first we establish the session variables
// that can be accessed everyplace else in the site
// for this user session

session_start();
$_SESSION["email_original"] = $txt_email;
$_SESSION["password_original"] = $txt_password;
$_SESSION["bill_first_name"] = $txt_bill_first_name;
$_SESSION["bill_last_name"] = $txt_bill_last_name;
$_SESSION["bill_address"] = $txt_bill_address;
$_SESSION["bill_city"] = $txt_bill_city;
$_SESSION["bill_state"] = $sel_bill_state;
$_SESSION["bill_zip"] = $txt_bill_zip;
$_SESSION["bill_phone"] = $txt_bill_phone;
$_SESSION["bill_fax"] = $txt_bill_fax;
$_SESSION["ship_first_name"] = $txt_ship_first_name;
$_SESSION["ship_last_name"] = $txt_ship_last_name;
$_SESSION["ship_address"] = $txt_ship_address;
$_SESSION["ship_city"] = $txt_ship_city;
$_SESSION["ship_state"] = $sel_ship_state;
$_SESSION["ship_zip"] = $txt_ship_zip;
$_SESSION["ship_phone"] = $txt_ship_phone;
$_SESSION["ship_fax"] = $txt_ship_fax;
$_SESSION["card_name"] = $txt_card_name;
$_SESSION["card_type"] = $sel_card_type;
$_SESSION["card_number"] = $txt_card_number;
$_SESSION["card_month"] = $sel_card_month;
$_SESSION["card_year"] = $sel_card_year;
// now we should write the inputs to the profile table
// connecting to the database on battcave.com
$link = mysql_connect($host, $user, $password);
// creating the query string
$query_string = "INSERT INTO profile
VALUES ('0',
'$txt_email',
'$txt_password',
'$txt_bill_first_name',
'$txt_bill_last_name',
'$txt_bill_address',
'$txt_bill_city',
'$sel_bill_state',
'$txt_bill_zip',
'$txt_bill_phone',
'$txt_bill_fax',
'$txt_ship_first_name',
'$txt_ship_last_name',
'$txt_ship_address',
'$txt_ship_city',
'$sel_ship_state',
'$txt_ship_zip',
'$txt_ship_phone',
'$txt_ship_fax',
'$sel_card_type',
'$txt_card_number',
'$sel_card_month',
'$sel_card_year',
'$txt_card_name',
Now( ))";

// executing the SQL statement
mysql_db_query($db_name, $query_string, $link);

mysql_close($link);
header("location:checkout_profile_display.php");

}

}
?>
<br><br>
<div align="center">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0" cellpadding="6" cellspacing="0" width="600" id="table1">
<tr>
<td colspan = 2 align=center><b><font size="4">*</font> denotes a required entry</b></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*E-Mail Address:</font></td>
<td width="387">
<input type="text" name="txt_email" size="30" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_email'])) echo $_REQUEST['txt_email']; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Password:</font></td>
<td width="387">
<input type="password" name="txt_password" size="12" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_password'])) echo $_REQUEST['txt_password']; ?>"></td>
</tr>
<tr>
<td width="189" align="right">&nbsp;</td>
<td width="387">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><b>
<font size="5" color="#A36436">Billing Information</font></b></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Name:</font></td>
<td width="387">
<input name="txt_bill_first_name" size="15" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_bill_first_name'])) echo $_REQUEST['txt_bill_first_name']; ?>">
<input name="txt_bill_last_name" size="20" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_bill_last_name'])) echo $_REQUEST['txt_bill_last_name']; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Street Address:</font></td>
<td width="387">
<input name="txt_bill_address" size="40" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_bill_address'])) echo $_REQUEST['txt_bill_address']; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*City:</font></td>
<td width="387">
<input name="txt_bill_city" size="20" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_bill_city'])) echo $_REQUEST['txt_bill_city']; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*State:</font></td>
<td width="387">
<select size="1" name="sel_bill_state" style="font-size: 14pt">
<option value = "no_select" <?php if (($_REQUEST['sel_bill_state']) == 'no_select') echo 'selected'; ?>>Please Select</option>
<option value = "Alabama" <?php if (($_REQUEST['sel_bill_state']) == 'Alabama') echo 'selected'; ?>>Alabama</option>
<option value = "Alaska" <?php if (($_REQUEST['sel_bill_state']) == 'Alaska') echo 'selected'; ?>>Alaska</option>
<option value = "Arizona" <?php if (($_REQUEST['sel_bill_state']) == 'Arizona') echo 'selected'; ?>>Arizona</option>
<option value = "Arkansas" <?php if (($_REQUEST['sel_bill_state']) == 'Arkansas') echo 'selected'; ?>>Arkansas</option>
<option value = "California" <?php if (($_REQUEST['sel_bill_state']) == 'California') echo 'selected'; ?>>California</option>
<option value = "Colorado" <?php if (($_REQUEST['sel_bill_state']) == 'Colorado') echo 'selected'; ?>>Colorado</option>
<option value = "Connecticut" <?php if (($_REQUEST['sel_bill_state']) == 'Connecticut') echo 'selected'; ?>>Connecticut</option>
<option value = "Delaware" <?php if (($_REQUEST['sel_bill_state']) == 'Delaware') echo 'selected'; ?>>Delaware</option>
<option value = "Florida" <?php if (($_REQUEST['sel_bill_state']) == 'Florida') echo 'selected'; ?>>Florida</option>
<option value = "Georgia" <?php if (($_REQUEST['sel_bill_state']) == 'Georgia') echo 'selected'; ?>>Georgia</option>
<option value = "Hawaii" <?php if (($_REQUEST['sel_bill_state']) == 'Hawaii') echo 'selected'; ?>>Hawaii</option>
<option value = "Idaho" <?php if (($_REQUEST['sel_bill_state']) == 'Idaho') echo 'selected'; ?>>Idaho</option>
<option value = "Illinois" <?php if (($_REQUEST['sel_bill_state']) == 'Illinois') echo 'selected'; ?>>Illinois</option>
<option value = "Indiana" <?php if (($_REQUEST['sel_bill_state']) == 'Indiana') echo 'selected'; ?>>Indiana</option>
<option value = "Iowa" <?php if (($_REQUEST['sel_bill_state']) == 'Iowa') echo 'selected'; ?>>Iowa</option>
<option value = "Kansas" <?php if (($_REQUEST['sel_bill_state']) == 'Kansas') echo 'selected'; ?>>Kansas</option>
<option value = "Kentucky" <?php if (($_REQUEST['sel_bill_state']) == 'Kentucky') echo 'selected'; ?>>Kentucky</option>
<option value = "Louisiana" <?php if (($_REQUEST['sel_bill_state']) == 'Louisiana') echo 'selected'; ?>>Lousiiana</option>
<option value = "Maine" <?php if (($_REQUEST['sel_bill_state']) == 'Maine') echo 'selected'; ?>>Maine</option>
<option value = "Maryland" <?php if (($_REQUEST['sel_bill_state']) == 'Maryland') echo 'selected'; ?>>Maryland</option>
<option value = "Massachusetts" <?php if (($_REQUEST['sel_bill_state']) == 'Massachusetts') echo 'selected'; ?>>Massachusetts</option>
<option value = "Michigan" <?php if (($_REQUEST['sel_bill_state']) == 'Michigan') echo 'selected'; ?>>Michigan</option>
<option value = "Minnesota" <?php if (($_REQUEST['sel_bill_state']) == 'Minnesota') echo 'selected'; ?>>Minnesota</option>
<option value = "Mississippi" <?php if (($_REQUEST['sel_bill_state']) == 'Mississippi') echo 'selected'; ?>>Mississippi</option>
<option value = "Missouri" <?php if (($_REQUEST['sel_bill_state']) == 'Missouri') echo 'selected'; ?>>Missouri</option>
<option value = "Montana" <?php if (($_REQUEST['sel_bill_state']) == 'Montana') echo 'selected'; ?>>Montana</option>
<option value = "Nebraska" <?php if (($_REQUEST['sel_bill_state']) == 'Nebraska') echo 'selected'; ?>>Nebraska</option>
<option value = "Nevada" <?php if (($_REQUEST['sel_bill_state']) == 'Nevada') echo 'selected'; ?>>Nevada</option>
<option value = "NewHampshire" <?php if (($_REQUEST['sel_bill_state']) == 'NewHampshire') echo 'selected'; ?>>New Hampshire</option>
<option value = "NewJersey" <?php if (($_REQUEST['sel_bill_state']) == 'NewJersey') echo 'selected'; ?>>New Jersey</option>
<option value = "NewMexico" <?php if (($_REQUEST['sel_bill_state']) == 'NewMexico') echo 'selected'; ?>>New Mexico</option>
<option value = "NewYork" <?php if (($_REQUEST['sel_bill_state']) == 'NewYork') echo 'selected'; ?>>New York</option>
<option value = "NorthCarolina" <?php if (($_REQUEST['sel_bill_state']) == 'NorthCarolina') echo 'selected'; ?>>North Carolina</option>
<option value = "NorthDakota" <?php if (($_REQUEST['sel_bill_state']) == 'NorthDakota') echo 'selected'; ?>>North Dakota</option>
<option value = "Ohio" <?php if (($_REQUEST['sel_bill_state']) == 'Ohio') echo 'selected'; ?>>Ohio</option>
<option value = "Oklahoma" <?php if (($_REQUEST['sel_bill_state']) == 'Oklahoma') echo 'selected'; ?>>Oklahoma</option>
<option value = "Oregon" <?php if (($_REQUEST['sel_bill_state']) == 'Oregon') echo 'selected'; ?>>Oregon</option>
<option value = "Pennsylvania" <?php if (($_REQUEST['sel_bill_state']) == 'Pennsylvania') echo 'selected'; ?>>Pennsylvania</option>
<option value = "RhodeIsland" <?php if (($_REQUEST['sel_bill_state']) == 'RhodeIsland') echo 'selected'; ?>>Rhode Island</option>
<option value = "SouthCarolina" <?php if (($_REQUEST['sel_bill_state']) == 'SouthCarolina') echo 'selected'; ?>>South Carolina</option>
<option value = "SouthDakota" <?php if (($_REQUEST['sel_bill_state']) == 'SouthDakota') echo 'selected'; ?>>South Dakota</option>
<option value = "Tennessee" <?php if (($_REQUEST['sel_bill_state']) == 'Tennessee') echo 'selected'; ?>>Tennessee</option>
<option value = "Texas" <?php if (($_REQUEST['sel_bill_state']) == 'Texas') echo 'selected'; ?>>Texas</option>
<option value = "Utah" <?php if (($_REQUEST['sel_bill_state']) == 'Utah') echo 'selected'; ?>>Utah</option>
<option value = "Vermont" <?php if (($_REQUEST['sel_bill_state']) == 'Vermont') echo 'selected'; ?>>Vermont</option>
<option value = "Virginia" <?php if (($_REQUEST['sel_bill_state']) == 'Virginia') echo 'selected'; ?>>Virginia</option>
<option value = "Washington" <?php if (($_REQUEST['sel_bill_state']) == 'Washington') echo 'selected'; ?>>Washington</option>
<option value = "WestVirginia" <?php if (($_REQUEST['sel_bill_state']) == 'WestVirginia') echo 'selected'; ?>>West Virginia</option>
<option value = "Wisconsin" <?php if (($_REQUEST['sel_bill_state']) == 'Wisconsin') echo 'selected'; ?>>Wisconsin</option>
<option value = "Wyoming" <?php if (($_REQUEST['sel_bill_state']) == 'Wyoming') echo 'selected'; ?>>Wyoming</option>
</select></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Zip:</font></td>
<td width="387">
<input name="txt_bill_zip" size="10" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_bill_zip'])) echo $_REQUEST['txt_bill_zip']; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">Billing Phone:</font></td>
<td width="387">
<input name="txt_bill_phone" size="12" style="font-size: 14pt" value = "<?php if (isset($txt_bill_phone)) echo $txt_bill_phone; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">Billing Fax:</font></td>
<td width="387">
<input name="txt_bill_fax" size="12" style="font-size: 14pt" value = "<?php if (isset($txt_bill_fax)) echo $txt_bill_fax; ?>"></td>
</tr>
<tr>
<td width="189" align="right">&nbsp;</td>
<td width="387">&nbsp;</td>
</tr>
<tr>
<td align="center" colspan="2"><font size="5" color="#A36436">
<b>Shipping Information</font></b></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">Same as Billing:</font></td>
<td width="387">
<input type="checkbox" name="chk_same_as" value="repeat" style="font-size: 14pt" <?php if (($_REQUEST['chk_same_as']) == 'repeat' ) echo 'checked'; ?>></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Name:</font></td>
<td width="387">
<input name="txt_ship_first_name" size="15" style="font-size: 14pt" value = "<?php if (isset($txt_ship_first_name)) echo $txt_ship_first_name; ?>">
<input name="txt_ship_last_name" size="20" style="font-size: 14pt" value = "<?php if (isset($txt_ship_last_name)) echo $txt_ship_last_name; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Street Address:</font></td>
<td width="387">
<input name="txt_ship_address" size="40" style="font-size: 14pt" value = "<?php if (isset($txt_ship_address)) echo $txt_ship_address; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*City:</font></td>
<td width="387">
<input name="txt_ship_city" size="20" style="font-size: 14pt" value = "<?php if (isset($txt_ship_city)) echo $txt_ship_city; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*State:</font></td>
<td width="387">
<select size="1" name="sel_ship_state" style="font-size: 14pt">
<option value = "no_select" <?php if (($sel_ship_state) == 'no_select') echo 'selected'; ?>>Please Select</option>
<option value = "Alabama" <?php if (($sel_ship_state) == 'Alabama') echo 'selected'; ?>>Alabama</option>
<option value = "Alaska" <?php if (($sel_ship_state) == 'Alaska') echo 'selected'; ?>>Alaska</option>
<option value = "Arizona" <?php if (($sel_ship_state) == 'Arizona') echo 'selected'; ?>>Arizona</option>
<option value = "Arkansas" <?php if (($sel_ship_state) == 'Arkansas') echo 'selected'; ?>>Arkansas</option>
<option value = "California" <?php if (($sel_ship_state) == 'California') echo 'selected'; ?>>California</option>
<option value = "Colorado" <?php if (($sel_ship_state) == 'Colorado') echo 'selected'; ?>>Colorado</option>
<option value = "Connecticut" <?php if (($sel_ship_state) == 'Connecticut') echo 'selected'; ?>>Connecticut</option>
<option value = "Delaware" <?php if (($sel_ship_state) == 'Delaware') echo 'selected'; ?>>Delaware</option>
<option value = "Florida" <?php if (($sel_ship_state) == 'Florida') echo 'selected'; ?>>Florida</option>
<option value = "Georgia" <?php if (($sel_ship_state) == 'Georgia') echo 'selected'; ?>>Georgia</option>
<option value = "Hawaii" <?php if (($sel_ship_state) == 'Hawaii') echo 'selected'; ?>>Hawaii</option>
<option value = "Idaho" <?php if (($sel_ship_state) == 'Idaho') echo 'selected'; ?>>Idaho</option>
<option value = "Illinois" <?php if (($sel_ship_state) == 'Illinois') echo 'selected'; ?>>Illinois</option>
<option value = "Indiana" <?php if (($sel_ship_state) == 'Indiana') echo 'selected'; ?>>Indiana</option>
<option value = "Iowa" <?php if (($sel_ship_state) == 'Iowa') echo 'selected'; ?>>Iowa</option>
<option value = "Kansas" <?php if (($sel_ship_state) == 'Kansas') echo 'selected'; ?>>Kansas</option>
<option value = "Kentucky" <?php if (($sel_ship_state) == 'Kentucky') echo 'selected'; ?>>Kentucky</option>
<option value = "Louisiana" <?php if (($sel_ship_state) == 'Louisiana') echo 'selected'; ?>>Lousiiana</option>
<option value = "Maine" <?php if (($sel_ship_state) == 'Maine') echo 'selected'; ?>>Maine</option>
<option value = "Maryland" <?php if (($sel_ship_state) == 'Maryland') echo 'selected'; ?>>Maryland</option>
<option value = "Massachusetts" <?php if (($sel_ship_state) == 'Massachusetts') echo 'selected'; ?>>Massachusetts</option>
<option value = "Michigan" <?php if (($sel_ship_state) == 'Michigan') echo 'selected'; ?>>Michigan</option>
<option value = "Minnesota" <?php if (($sel_ship_state) == 'Minnesota') echo 'selected'; ?>>Minnesota</option>
<option value = "Mississippi" <?php if (($sel_ship_state) == 'Mississippi') echo 'selected'; ?>>Mississippi</option>
<option value = "Missouri" <?php if (($sel_ship_state) == 'Missouri') echo 'selected'; ?>>Missouri</option>
<option value = "Montana" <?php if (($sel_ship_state) == 'Montana') echo 'selected'; ?>>Montana</option>
<option value = "Nebraska" <?php if (($sel_ship_state) == 'Nebraska') echo 'selected'; ?>>Nebraska</option>
<option value = "Nevada" <?php if (($sel_ship_state) == 'Nevada') echo 'selected'; ?>>Nevada</option>
<option value = "NewHampshire" <?php if (($sel_ship_state) == 'NewHampshire') echo 'selected'; ?>>New Hampshire</option>
<option value = "NewJersey" <?php if (($sel_ship_state) == 'NewJersey') echo 'selected'; ?>>New Jersey</option>
<option value = "NewMexico" <?php if (($sel_ship_state) == 'NewMexico') echo 'selected'; ?>>New Mexico</option>
<option value = "NewYork" <?php if (($sel_ship_state) == 'NewYork') echo 'selected'; ?>>New York</option>
<option value = "NorthCarolina" <?php if (($sel_ship_state) == 'NorthCarolina') echo 'selected'; ?>>North Carolina</option>
<option value = "NorthDakota" <?php if (($sel_ship_state) == 'NorthDakota') echo 'selected'; ?>>North Dakota</option>
<option value = "Ohio" <?php if (($sel_ship_state) == 'Ohio') echo 'selected'; ?>>Ohio</option>
<option value = "Oklahoma" <?php if (($sel_ship_state) == 'Oklahoma') echo 'selected'; ?>>Oklahoma</option>
<option value = "Oregon" <?php if (($sel_ship_state) == 'Oregon') echo 'selected'; ?>>Oregon</option>
<option value = "Pennsylvania" <?php if (($sel_ship_state) == 'Pennsylvania') echo 'selected'; ?>>Pennsylvania</option>
<option value = "RhodeIsland" <?php if (($sel_ship_state) == 'RhodeIsland') echo 'selected'; ?>>Rhode Island</option>
<option value = "SouthCarolina" <?php if (($sel_ship_state) == 'SouthCarolina') echo 'selected'; ?>>South Carolina</option>
<option value = "SouthDakota" <?php if (($sel_ship_state) == 'SouthDakota') echo 'selected'; ?>>South Dakota</option>
<option value = "Tennessee" <?php if (($sel_ship_state) == 'Tennessee') echo 'selected'; ?>>Tennessee</option>
<option value = "Texas" <?php if (($sel_ship_state) == 'Texas') echo 'selected'; ?>>Texas</option>
<option value = "Utah" <?php if (($sel_ship_state) == 'Utah') echo 'selected'; ?>>Utah</option>
<option value = "Vermont" <?php if (($sel_ship_state) == 'Vermont') echo 'selected'; ?>>Vermont</option>
<option value = "Virginia" <?php if (($sel_ship_state) == 'Virginia') echo 'selected'; ?>>Virginia</option>
<option value = "Washington" <?php if (($sel_ship_state) == 'Washington') echo 'selected'; ?>>Washington</option>
<option value = "WestVirginia" <?php if (($sel_ship_state) == 'WestVirginia') echo 'selected'; ?>>West Virginia</option>
<option value = "Wisconsin" <?php if (($sel_ship_state) == 'Wisconsin') echo 'selected'; ?>>Wisconsin</option>
<option value = "Wyoming" <?php if (($sel_ship_state) == 'Wyoming') echo 'selected'; ?>>Wyoming</option>
</select></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Zip:</font></td>
<td width="387">
<input name="txt_ship_zip" size="10" style="font-size: 14pt" value = "<?php if (isset($txt_ship_zip)) echo $txt_ship_zip; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">Shipping Phone:</font></td>
<td width="387">
<input name="txt_ship_phone" size="12" style="font-size: 14pt" value = "<?php if (isset($txt_ship_phone)) echo $txt_ship_phone; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">Shipping Fax:</font></td>
<td width="387">
<input name="txt_ship_fax" size="12" style="font-size: 14pt" value = "<?php if (isset($txt_ship_fax)) echo $txt_ship_fax; ?>"></td>
</tr>
<tr>
<td width="189" align="right">&nbsp;</td>
<td width="387">&nbsp;</td>
</tr>
<tr>
<td width="576" align="center" colspan="2">
<font size="5" color="#A36436"><b>Credit Card Information</font></b></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Name on Card:</font></td>
<td width="387">
<input name="txt_card_name" size="40" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_card_name'])) echo $_REQUEST['txt_card_name']; ?>">
</td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Card Type:</font></td>
<td width="387">
<select size="1" name="sel_card_type" style="font-size: 14pt">
<option value = "no_select" <?php if (($_REQUEST['sel_card_type']) == 'no_select') echo 'selected'; ?>>Please Select</option>
<option value = "AmEx" <?php if (($_REQUEST['sel_card_type']) == 'AmEx') echo 'selected'; ?>>American Express</option>
<option value = "Discover" <?php if (($_REQUEST['sel_card_type']) == 'Discover') echo 'selected'; ?>>Discover</option>
<option value = "Mastercard" <?php if (($_REQUEST['sel_card_type']) == 'Mastercard') echo 'selected'; ?>>Mastercard</option>
<option value = "Visa" <?php if (($_REQUEST['sel_card_type']) == 'Visa') echo 'selected'; ?>>Visa</option>
</select></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Card Number:</font></td>
<td width="387">
<input name="txt_card_number" size="20" style="font-size: 14pt" value = "<?php if (isset($_REQUEST['txt_card_number'])) echo $_REQUEST['txt_card_number']; ?>"></td>
</tr>
<tr>
<td width="189" align="right"><font size="4">*Expiration Date:</font></td>
<td width="387">
<select size="1" name="sel_card_month" style="font-size: 14pt">
<option value = "January" <?php if (($_REQUEST['sel_card_month']) == 'January') echo 'selected'; ?>>January</option>
<option value = "February" <?php if (($_REQUEST['sel_card_month']) == 'February') echo 'selected'; ?>>February</option>
<option value = "March" <?php if (($_REQUEST['sel_card_month']) == 'March') echo 'selected'; ?>>March</option>
<option value = "April" <?php if (($_REQUEST['sel_card_month']) == 'April') echo 'selected'; ?>>April</option>
<option value = "May" <?php if (($_REQUEST['sel_card_month']) == 'May') echo 'selected'; ?>>May</option>
<option value = "June" <?php if (($_REQUEST['sel_card_month']) == 'June') echo 'selected'; ?>>June</option>
<option value = "July" <?php if (($_REQUEST['sel_card_month']) == 'July') echo 'selected'; ?>>July</option>
<option value = "August" <?php if (($_REQUEST['sel_card_month']) == 'August') echo 'selected'; ?>>August</option>
<option value = "September" <?php if (($_REQUEST['sel_card_month']) == 'September') echo 'selected'; ?>>September</option>
<option value = "October" <?php if (($_REQUEST['sel_card_month']) == 'October') echo 'selected'; ?>>October</option>
<option value = "November" <?php if (($_REQUEST['sel_card_month']) == 'November') echo 'selected'; ?>>November</option>
<option value = "December" <?php if (($_REQUEST['sel_card_month']) == 'December') echo 'selected'; ?>>December</option>
</select>
<select size="1" name="sel_card_year" style="font-size: 14pt">
<option value = "2004" <?php if (($_REQUEST['sel_card_year']) == '2004') echo 'selected'; ?>>2004</option>
<option value = "2005" <?php if (($_REQUEST['sel_card_year']) == '2005') echo 'selected'; ?>>2005</option>
<option value = "2006" <?php if (($_REQUEST['sel_card_year']) == '2006') echo 'selected'; ?>>2006</option>
<option value = "2007" <?php if (($_REQUEST['sel_card_year']) == '2007') echo 'selected'; ?>>2007</option>
<option value = "2008" <?php if (($_REQUEST['sel_card_year']) == '2008') echo 'selected'; ?>>2008</option>
<option value = "2009" <?php if (($_REQUEST['sel_card_year']) == '2009') echo 'selected'; ?>>2009</option>
<option value = "2010" <?php if (($_REQUEST['sel_card_year']) == '2010') echo 'selected'; ?>>2010</option>
</select></td>
</tr>
<tr>
<td width="189" align="right">&nbsp;</td>
<td width="387">&nbsp;</td>
</tr>
<tr>
<td width="576" align="center" colspan="2">
<input type="submit" value="Submit" name="submit_new_profile" style="font-size: 14pt; font-weight: bold"></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
</div>

</body>
</html>

 

This is essentially the same as the profile_new.php so it won't be discussed in much detail at all at present.  It operates in all the same ways to validate the user's inputs and give them feedback about any problems.  The only real things that are most important to notice are
  • setting up all the session variables baed on the shopper's inputs for easier reference in future pages
  • redirecting the shopper to checkout_profile_display.php where the shopper's billing information will be displayed.

Now we want to take the other branch where the shopper tries to access an existing profile.  We need a variety of pages to deal with all the possible outcomes associated with a shopper's inputs.  The main page of interest in this section is checkout_profile_access_validate.php.  This PHP file queries the profile table to see whether the shopper's inputs can be found and redirects the shopper to other pages based on the input's validity.  We will discuss this page in more detail after it is used because it is more original in this section.

 

<html>
<?php
include("includes/connection_config.php");
//  set the inputted email and password to session variable for later use
session_start();
$_SESSION["email_original"] = $txt_original_email;
$_SESSION["password_original"] = $txt_original_password;
// need to connect to the current data to make sure
// that the email address hasn't already been used

// connecting to the database on battcave.com
$link = mysql_connect($host, $user, $password);
// creating the query string
$query_string = "SELECT * FROM profile WHERE (email = '$txt_original_email' AND password = '$txt_original_password')";
// executing the SQL statement
$result_set = mysql_db_query($db_name, $query_string, $link);
// if the resultset has any entries then you need to let the Shopper
// know the email address is already in use

if ($row = mysql_fetch_array($result_set))
{

session_start();
$_SESSION["email_original"] = $row[email];
$_SESSION["password_original"] = $row[password];
$_SESSION["bill_first_name"] = $row[bill_first_name];
$_SESSION["bill_last_name"] = $row[bill_last_name];
$_SESSION["bill_address"] = $row[bill_address];
$_SESSION["bill_city"] = $row[bill_city];
$_SESSION["bill_state"] = $row[bill_state];
$_SESSION["bill_zip"] = $row[bill_zipcode];
$_SESSION["bill_phone"] = $row[bill_phone];
$_SESSION["bill_fax"] = $row[bill_fax];
$_SESSION["ship_first_name"] = $row[ship_first_name];
$_SESSION["ship_last_name"] = $row[ship_last_name];
$_SESSION["ship_address"] = $row[ship_address];
$_SESSION["ship_city"] = $row[ship_city];
$_SESSION["ship_state"] = $row[ship_state];
$_SESSION["ship_zip"] = $row[ship_zipcode];
$_SESSION["ship_phone"] = $row[ship_phone];
$_SESSION["ship_fax"] = $row[ship_fax];
$_SESSION["card_name"] = $row[card_name];
$_SESSION["card_type"] = $row[card_type];
$_SESSION["card_number"] = $row[card_number];
$_SESSION["card_month"] = $row[expiration_month];
$_SESSION["card_year"] = $row[expiration_year];
mysql_close($link);
header("location:checkout_profile_display.php");

}
else
{

mysql_close($link);
header("location:checkout_profile_access_failed.php");

}
?>
</body>
</html>

 

What the page does is it basically
  • takes the email and password entered by the shopper and queries whether they are in the profile table
  • if they are in the table
    • the resultset is used to establish the $_SESSION variables to be used in the rest of the checkout process
      • billing information
      • shipping information
      • credit card information
    • then the shopper is redirected to profile_checkout_display.php where certain information about the shopper will be displayed
  • if they aren't in the table
    • the shopper is redirected to checkout_profile_access_failed.php which will help the shopper try some other entries or get their password emailed.

Since it is the easier to work with we will next present the checkout_profile_access_failed.php where the shopper is redirected to try again.

 

<html>
<!-- profile_access_failed.php - accessing a profile -->
<head>
<title>Accessing a Profile</title>
</head>
<?php
include("includes/header.php");
?>

<br><p align="center"><font size=5 color="#FF0000"><b>The email and password you entered<br>
were not found in our database.</b></font></p>
<div align="center">
<table border="0" cellpadding="3" cellspacing="0" align="center" width="400" id="layout_table">
<tr>
<td width="400" align="center"><b><font size="4" color="#999966">Access an
Existing Profile<br></font></b></td>
</tr>
<tr>
<td width="400">
<form method="POST" action="checkout_profile_access_validate.php">
<div align="center">
<table border="0" cellpadding="5" cellspacing="0" width="400" id="table_access">
<tr>
<td width="175" align=right><b><font size="4">E-Mail:</font></b></td>
<td width="225">
<input type="text" name="txt_original_email" size="30" style="font-size: 14pt"></td>
</tr>
<tr>
<td width="175" align="right"><b><font size="4">Password:</font></b></td>
<td width="225">
<input type="password" name="txt_original_password" size="12" style="font-size: 14pt"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit" name="cmd_access_profile" style="font-size: 14pt; font-weight: bold"></td>
</tr>
</table>
</div>
</form>
</td>
</tr>
<tr>
<td align="center"><font color="#999966"><b>Forgotten your password,
<a href="email_password.php">click here</a>?</b></font></td>
</tr>
</table>
</div>
</body>
</html>

 

This is largely an HTML form page that allows the shopper to try again or try to get their password emailed to them if the database contains their email address. The email_password related pages are the same as those used when trying to update a profile in the profile section and won't be presented again.

This checkout_profile_access_failed.php page should look like the following.

 

 

This form allows the user to try again or try to get their password emailed to them.

These are the only PHP pages we will present on this webpage.  Next we will move to the checkout_profile_display.php that will display billing information before going on in the checkout process.