User Registration - Part 1
The basics of developing a user registration system using ASP
Several server side programs and scripts will have to be implemented to make the florist web site functional. We will implement an application that processes the user's form entries and enters them into the database, an application that validates login, a 'shopping cart' type application that keeps track of the user's order, and a script that displays items from the database on the Internet Browser Window. Sometimes, more that one script may be necessary to get an application to work. For example, the shopping cart application uses four scripts - a script that allows users to view the contents of the cart, a script that adds items to the cart, a scrit that delete items from the cart, and a script that places orders. Also, it is near impossible to restrict ASP code to the main scripts and restrasin display to plain HTML. Very often, the response has to reflect the status of the previous operation or a change made by the user and this involves adding ASP statements that print a message based on user input or ASP database operations that retrieve user's data into the response HTML. Since Visual Basic is the language used for ASP scripting, you may find the VB Script Programming Reference very useful.
User Registration
The concept of user registration is central to many e-commerce sites. Users may browse through certain parts of the domain (catalogues, bulletin boards etc.) without having to sign up but are asked to login or register if they wish to order goods or access in-depth information. At this point, the user may register with the site if he or she does not have a login ID. While registering, the user may be asked to enter personal details along with a new login ID and password. The domain saves this information for later use.
We have designed a Registration Form for the florist web site and stipulated input conditions through Javascript validation. We have also set up the 'users' database table to receive information. Let us now work on writing a script that will process submitted forms. The first step to writing a program is to design the control flow. The control flow for the registration program will look something like the following:
get form data enter data into database
The above flow seems pretty simple to code. However, we have not really thought about the design. For one, the person who has submitted the form may not be a first time user; she may simply want her phone number updated. So, we have to deal with two types of data entry in the control flow - an INSERT that adds a new row and UPDATE that modifies existing information
get form data
if user is currently logged in
Update data for the user to reflect form data
Otherwise
Enter data into database
Looking at the conditional part of the flow makes us aware of another eventuality. What if two users choose the same login name? Login names should obviously be unique. Let us modify the flow to reflect this.
get form data
if the user is a new user then
if the 'login' entered already exists in database
send a response asking the user to choose another login
Otherwise
Enter data into database
else if the user is currently logged in
Update data for the user to reflect form data
send a success message to the user after data has been entered/updated.
We are now ready to write the script. First, double click on Visual Web Developer to get it running. Once you see the initial page, go to the file menu and select 'open web site'. In the pop up window, select the Inetpub\wwwroot\florist directory. All the files in the directory will be listed on the right hand window. You may open and edit as many files as you wish at a time. Now, go back to the file menu and select 'New File'. Since the ASP template does not appear by default, simply select the second template in the list (HTML page). However, specify the name 'saveuser.asp'. An empty html file will appear. Remove all the tags except the initial <! DOCTYPE directive. Now, let us start adding our script portion by portion. As we go along, cut and paste the code into the new saveuser.asp file.
<dim login,lname, fname, phone, gender, favflowers,
message, bmonth, bday
lname = replace(request.form("lname"),"'","`",1,-1,1)
fname = replace(request.form("fname"),"'","`",1,-1,1)
phone = request.form("phone")
gender = request.form("gender")
favflowers = request.Form("likes")
message = replace(request.form("message"),"'","`",1,-1,1)
bmonth = request.form("month")
bday = request.form("day")
birthday = bmonth & "-" & bday