Hi!
I'm new to ASP and am trying to simulate a typical ecommerce site. I've got the register.asp and adduser.asp pages. The user fills in the register.asp and submits the data which is processed by adduser.asp. I'm following closely on the examply provided in "Beginning ASP 3.0" from Wrox press. For some reason I can't make out, my code doesn't work. :-( Can anyone help?
Here's the register.asp page:
[bold]And here's the adduser.asp page: [/bold]
and here's the datastore.asp:
I'm new to ASP and am trying to simulate a typical ecommerce site. I've got the register.asp and adduser.asp pages. The user fills in the register.asp and submits the data which is processed by adduser.asp. I'm following closely on the examply provided in "Beginning ASP 3.0" from Wrox press. For some reason I can't make out, my code doesn't work. :-( Can anyone help?
Here's the register.asp page:
Code:
<BASEFONT FACE="Comic Sans MS" COLOR="DarkBlue">
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
function VerifyData() // This just makes sure that that password and
{ // verify passwords values match.
if (document.frmUser.Password.value != document.frmUser.VerifyPassword.value)
{
alert ("Your password and verified password do not match - please reenter");
return false;
}
else
return true;
}
-->
</SCRIPT>
<TITLE>Sasikanth Malladi's Online Videostore - User Registration</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFF80">
<CENTER>
<%
If Request("Update") = "True" Then
Response.Write "<H1>Video Store<BR> Update User Registration</H1>"
Else
Response.Write "<H1>Video Store<BR> New User Registration</H1>"
End If
%>
</CENTER>
<P>
<%
' The following piece of code checks for info update
' or registration.
If Request("Update") = "True" Then
Response.Write "Please change your registration information as listed below<P>"
Else
If Request("NotFound") = "True" Then
Response.Write "<I>We were unable to locate your information. " & _
"Please take the time to register again.</I><P>"
Else
Response.Write "<CENTER>(If you're already registered with us, " & _
"then click the 'Login' link below.)</CENTER><P>"
End If
Response.Write "You only need to register with our system if you want to " & _
"buy videos with us. <BR> " & _
"In order to use these services, please take a few minutes " & _
"to complete the form below. Once you have done that, " & _
"you will have full access to the system."
End If
%>
<FORM ACTION="AddUser.asp" NAME="frmUser" METHOD="POST" onSubmit="return VerifyData()">
<TABLE BORDER=0>
<TR>
<TD WIDTH=20% ROWSPAN=11> </TD>
<TD>E-Mail Address:</TD>
<TD><INPUT TYPE="Text" NAME="email" VALUE="<%= Session("EMailAddress")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>Given Name:</TD>
<TD><INPUT TYPE="Text" NAME="GivenName" VALUE="<%= Session("GivenName")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>Family Name:</TD>
<TD><INPUT TYPE="Text" NAME="FamilyName" VALUE="<%= Session("FamilyName")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>Address:</TD>
<TD><INPUT TYPE="Text" NAME="Address1" VALUE="<%= Session("StreetAddress1")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD></TD>
<TD><INPUT TYPE="Text" NAME="Address2" VALUE="<%= Session("StreetAddress2")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>City:</TD>
<TD><INPUT TYPE="Text" NAME="City" VALUE="<%= Session("City")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>State:</TD>
<TD><INPUT TYPE="Text" NAME="State" VALUE="<%= Session("State")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>Postal Code:</TD>
<TD><INPUT TYPE="Text" NAME="PostalCode" VALUE="<%= Session("PostalCode")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD>Country:</TD>
<TD><INPUT TYPE="Text" NAME="Country" VALUE="<%= Session("Country")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD> <P>Password:</TD>
<TD VALIGN=bottom><INPUT TYPE="Password" NAME="Password" SIZE="40"></TD>
</TR>
<TR>
<TD>Verify Password:</TD>
<TD><INPUT TYPE="Password" NAME="VerifyPassword" SIZE="40"></TD>
</TR>
<TR>
<TD ALIGN=CENTER COLSPAN=2><BR>
<INPUT TYPE="Submit" VALUE="Submit Registration">
<INPUT TYPE="RESET"></TD>
</TR>
</TABLE>
</FORM>
<HR><CENTER>
<TABLE WIDTH=80%><TR><TD>
<A HREF="Default.asp"> Home </A> </TD> <TD><A HREF="login.asp"> Login </A></TD>
</TABLE></CENTER>
</BODY>
</HTML>
Code:
<%'!--#include file="Datastore.asp"--%>
<%
Dim rsUsers ' Declaring a record set object of users
' This will be used to interact with the User table
Set rsUsers = Server.CreateObject ("ADODB.Recordset")
' and initializing it with the server object method
rsUsers.Open "Person",objConn,adOpenForwardOnly,adLockOptimistic,adCmdTable
' The Open method will populate the record set with the User
' table. adLockOptimistic allows us to write info to the
' table.adOpenForwardOnly allows to only move forward in the table
If Session("PersonID") <> "" Then ' currently logged on user
rsUsers.Filter = "PersonID= '" & Session("PersonID") & "'"
' set the filter so that only this person's record is open
' this filter is set by the Filter property of the RS object
' This is done by getting the Session's PersonID and filtering
' the RS using this PersonID
Else ' If Session("PersonID") is not available, use the email addr
' and password to set the filter.
rsUsers.Filter = "EMailAddress '" & Request.Form("email") & "'" & _
"AND Password = '" & Request.Form ("Password") & "'"
If rsUsers.EOF Then
' if email addr and password not found, add new user.
rsUsers.AddNew
' Else
' Email address and password matched with DB records
' In this case we'll the user to allow personal details
End If
End If
' Now write the details to the Person table
rsUsers("EMailAddress") = Request.Form ("email")
rsUsers("Password") = Request.Form ("Password")
rsUsers("GivenName") = Request.Form ("FamilyName")
rsUsers("FamilyName") = Request.Form ("GivenName")
rsUsers("StreetAddress1") = Request.Form ("Address1")
rsUsers("StreetAddress2") = Request.Form ("Address2")
rsUsers("City") = Request.Form ("City")
rsUsers("State") = Request.Form ("State")
rsUsers("PostalCode") = Request.Form ("PostalCode")
rsUsers("Country") = Request.Form ("Country")
rsUsers("Active") = True
rsUsers("LastLogin") = Now
rsUsers.Update
' Done. Update the table
' Now write all this info into the session level variables
Dim strName, strValue
' Each RS object has its own Fields collections, which corresponds to the
' fields in the database table which we're currently referring to. This
' fields collection corresonds to the record we're referring to in the table.
For each strField in rsUsers.Fields
strName = strField.Name ' Name of the field. PersonID, email address, etc.
strValue = strField.value ' and the corresponding values.
Session(strName) = strValue ' put them into the current session object
' Now the user is logged-in and an active session is in progress.
Next ' end for
Session("blnValidUser") = True 'valid current user.
Response.Redirect "MenuForRegisteredUsers.asp"
' Now for what all a regd user can do!
%>
Code:
<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!-- The above file contains all the constants used as parameters when
working with the ADODB objects. -->
<%
Dim objConn' 'declare a variable that will hold the DB connection
Set objConn = Server.CreateObject("ADODB.Connection")
' and create the connection object
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Inetpub\[URL unfurl="true"]wwwroot\smalladi\videostore\Movie2000.mdb"[/URL]
' blnValidUser is a Session variable that's True if a person is logged in
' i.e. an active session.
If Session("blnValidUser") = True and Session("PersonID") = "" Then
' if session is active and PersonID is blank, then fetch that person's info
Dim rsPersonIDCheck ' create a record set to hold that person's info
Set rsPersonIDCheck = Server.CreateObject("ADODB.Recordset")
Dim strSQL
strSQL = "SELECT PersonID FROM Person " & _
"WHERE EMailAddress = '" & Session("EMailAddress") & "';"
rsPersonIDCheck.Open strSQL, objConn ' populate the RS object
If rsPersonIDCheck.EOF Then
' if the email is invalid, we log out the person
Session("blnValidUser") = False
Else
Session("PersonID") = rsPersonIDCheck("PersonID")
End If
rsPersonIDCheck.Close
Set rsPersonIDCheck = Nothing
End If
%>