Shoppers Updating their Profiles
Introduction.
Now we need to develop the page associated with a shopper updating 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. In our previous pages where we were trying to work with a shopper entering their profile for the first time, we put almost all of the processing within the page profile_new.php. Now we will separate out the processing into a variety of pages that write to each other to illustrate a different approach and simplify the coding in individual pages at least somewhat. Overall we need to be able to do several things.
The following diagram illustrates how these pages interact. |
This approach involves quite a few different PHP pages
interacting, posting and sharing information with each other.
Sometimes, this information will be posted from a form to another page,
other times we will make sue of session variables to make sure the
information is available when it is needed. Remember we have
It is important to keep your eyes open about what is defined, updatable and accessible where. So this webpage will be quite large because we have so many pages to develop. This next table contains a set of code for where the shopper is routed if their email and password aren't found in our profile table. You need to call this page profile_access_failed.php. |
<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="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 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 will look like the following and give the shopper the option of trying again or just having firefox email them their password to the email address they enter. |
Now we need to do the processing that validates
whether the shopper has entered information we have in our database.
This will be done in the following processing validation page, that
only redirects shoppers to other form pages based on what is found
in the database. You should call this page profile_access_validate.php. |
<html> <?php include("includes/connection_config.php"); ?> <body> <?php 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 (mysql_fetch_array($result_set)) { mysql_close($link); header("location:profile_update.php"); } else { mysql_close($link); header("location:profile_access_failed.php"); } ?> </body> </html> |
Notice how this redirects the shopper to either
profile_access_failed.php or profile_update.php depending on whether
the shopper's entries are found. But, the major and most complicated task for this webpage is to update an existing profile. The next table contains the code for profile_update.php. This is primarily a page that retrieves a valid shopper's profile info so that the shopper can modify it and update it. The validation and processing is done on a separate page. Even though it might result in word wrap, I try to make sure to represent the control/looping/decision structures using indenting. |
<html> <!-- profile_update.php - the form page for updating a profile --> <head><title>Updating Your Profile at Firefox</title></head> <?php include("includes/header.php"); include("includes/connection_config.php"); // creating the variables to hold the email and password // entered for validation session_start(); $txt_original_email = $_SESSION["email_original"]; $txt_original_password = $_SESSION["password_original"]; // if an error message was developed in the processing page it is displayed if ($_SESSION["error_message"] != "") {
}
} |
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.
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 PHP related to processing this form and either accumulating the error message to feedback to the user or updating the info they've provided in the database. Though there are other fairly important components relating to verifying the email address isn't being used by someone else and providing session variables for use elsewhere. But you should call this page profile_update_process.php. |
<html> <!-- profile_update_process.php - the processing page for updating a profile --> <?php include("includes/connection_config.php"); ?> <body> <?php // creating the variables to hold the email and password // entered for validation session_start(); $txt_original_email = $_SESSION["email_original"]; $txt_original_password = $_SESSION["password_original"]; // 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 = ""; // if it has been submitted // each of the form entries will be examined // to see which have been omitted if ($txt_email == "") {
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
} |
This processing script can be looked at as
having two overall purposes.
Now we start the more detailed code discussion.
Now we need to develop the profile_updated.php which largely gives the shopper feedback about the success of their update. |
<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 Updated</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. |