Shopper Access to their Profile

 

Introduction.  Now we need to develop the page associated with a shopper adding their profile.  While we intend on having steps within the checkout process where the shopper can access or initiate their profile, these will be developed when we develop the checkout process.  Presently, we are concerned with shoppers that aren't in the check out process.

This code is really quite complex because we need to do a number of things.

  • have a form for the shopper's inputs
    • provide the capability for the shopper to make their shipping information the same as/differ from their billing information
  • provide input validation on the form
    • make sure required entries have inputs
    • make sure the email address isn't already in the table
    • make sure the credit card expiration date hasn't passed
  • have the form be sticky for when the shopper is given feedback
  • actually insert the data into the profile table after it passes all the input validation

We have chosen to develop a form that posts to itself in order to make things more self contained.  Unfortunately, this requires more cleverness from the developer than most other strategies, but it seems worth the effort.

The next table contains the code for profile_new.php.  I have chosen to present the indentations associated with the looping and decision structures even though this means that much of the code gets wrapped across lines.  I will try to reduce the size of some text to help this, but it doesn't work as well as you might hope.  There is also quite a bit of HTML code associated with the form itself since we are making use of selects to do things like assist state identification.  If you want me to email a copy of the code to you directly, let me know.

 

<html>
<!-- profile_new.php - the form page for creatign 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["active_profile"] = "active";
$_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;
// 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:profile_added.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 first image displays the initial form.

 

 

When the error messages appear, they do so in red above the form.  Here I have left just about everything blank except for using an email that has been used before.

 

 

Now, we attempt to describe the code.

Generally, the page can be broken down into a section involving most of executable PHP code.  The lower portion relates primarily to the form itself and making the form sticky.  We will focus on the PHP code that does most of the processing for this writing.  But, we will discuss the sticky form in class.

  • Initially we establish the page and include the header.php
  • We start by initializing our error_message as blank
  • Then we work the input validation and insertion related code only if the form has been submitted.
    • First we test to see if the email entry is blank
      • if it is we append appropriate words to the error_message
      • if it isn't we connect to our profile table and query to find out whether the email address has been used before
        • if the email address has been used before we append this to our error_message
    • Then we test to see if the password is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the billing first name is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the billing last name is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the billing address is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the billing city is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the billing state has been selected
      • if it isn't we append appropriate words to the error_message
    • Then we test to see if the billing zip is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the credit card name is blank
      • if it is we append appropriate words to the error_message
    • Then we test to see if the credit card type is selected
      • if it isn't we append appropriate words to the error_message
    • Now we test to see if the credit card expiration date is after today's date
      • we parse the current month and year
      • we convert the month to appropriate numbers
      • we make a comparison between the current date and the expiration month and year selected by the shopper - if it fails we append an appropriate error message
    • Now we test to see whether the shopper has checked that the shipping address for the profile is the same as the billing address
      • if it is we assign the values appropriately
      • if it isn't, we need to check the shipping entries
        • Then we test to see if the billing first name is blank
          • if it is we append appropriate words to the error_message
        • Then we test to see if the billing last name is blank
          • if it is we append appropriate words to the error_message
        • Then we test to see if the billing address is blank
          • if it is we append appropriate words to the error_message
        • Then we test to see if the billing city is blank
          • if it is we append appropriate words to the error_message
        • Then we test to see if the billing state has been selected
          • if it isn't we append appropriate words to the error_message
        • Then we test to see if the billing zip is blank
          • if it is we append appropriate words to the error_message
    • If the error_message has anything in it then we display it in red
    • Else we
      • assign the session variables that will be used to automatically fill in appropriate values during checkout
      • make a connection to our database profile table
      • insert the shopper's inputs into the profile table
      • redirect the shopper to the profile_added.php

Everything else relates to sticky form processing which we will leave for class, particularly since we have discussed these issues in earlier webpages.

Now we need to develop the profile_added.php which largely gives the shopper feedback about the success of their addition.

 

<html>
<head>
<title>Your Profile Has Been Added</title>
</head>
<?php
include("includes/header.php");
?>
<br><br>
<table cellpadding="5" border="0" width="750" align="center">
<tr><td align="center">
<font size="5" color="#990000"><b>Your Profile Has Been Added</b></font><br>
</td></tr>
<tr><td align="center">
<br><font size="4">You can continue shopping by using the links above.</font><br>
</td></tr>
<tr><td align="center">
<font size="4" color="#a66838">You can update your profile by clicking<br>
on the <a href="profile_access.php">profile</a> link and logging in<br>
using your email address and password</font>
</td></tr>
</table>
</body>
</html>

 

This page will look like the following.