Problem with adding user to database
Hello:
I am having problem in adding new user to database.
Here are files i am using.
login.asp:
<BASEFONT FACE="Comic Sans MS" COLOR="DarkBlue">
<HTML>
<HEAD>
<TITLE>Wrox Classifieds - Login</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFF80">
<CENTER><H1>Wrox Classifieds<BR>Login</H1></CENTER>
<P>
<%
If Request("SecondTry") = "True" Then ' User's second attempt at logging in
If Request("WrongPW") = "True" Then
Response.Write "Invalid Password. Please try again: " & _
"if you get it wrong we'll ask you to re-register.<BR>"
Else
Response.Write "E-Mail Address not found. Please try again: " & _
"if you get it wrong we'll ask you to re-register.<BR>"
End If
End If
Response.Write "Please enter your e-mail address and password " & _
"to login to the system."
%>
<FORM ACTION="CheckLogin.asp<% If Request("SecondTry")="True" Then
Response.Write "?SecondTry=True"
End If %>" METHOD="POST">
<TABLE BORDER=0>
<TR>
<TD>E-Mail Address:</TD>
<TD><INPUT TYPE="Text" NAME="email"
<% If Request("SecondTry") = "True" then %>
VALUE="<%= Session("EMailAddress") %>"
<% End If %>
SIZE="40"></TD>
</TR>
<TR>
<TD>Password:</TD>
<TD><INPUT TYPE="Password" NAME="Password" SIZE="40"></TD>
</TR>
<TR>
<TD></TD>
<TD align=center><INPUT TYPE="Submit" VALUE="Login">
<INPUT TYPE="RESET"></TD>
</TR>
</TABLE>
</FORM>
<TABLE BORDER=0 WIDTH=100%>
<TR ALIGN=CENTER>
<TD WIDTH=33%><A HREF="BrowseListings.asp">Browse the listings</A></TD>
<TD WIDTH=33%>Login</TD>
<TD WIDTH=33%><A HREF="Register.asp">I'm a new user</A></TD>
</TR>
</TABLE>
</BODY>
</HTML>
adduser.asp:
<%
Dim rsUsers
Set rsUsers = Server.CreateObject("ADODB.RecordSet")
rsUsers.Open "Person", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable
If Session("PersonID") <> "" Then ' currently logged-on user
rsUsers.Filter = "PersonID = '" & Session("PersonID") & "'"
Else ' New session
rsUsers.Filter = "EMailAddress = '" & Request.Form("email") & "'" & _
"AND Password = '" & Request.Form("password") & "'"
If rsUsers.EOF Then ' User not found
rsUsers.AddNew ' ...so add a new record
' Else
' Email address and password matched with DB records -
' In this case we'll allow this to update user's personal details
End If
End If
' write personal details to record
rsUsers("EMailAddress") = Request.Form("email")
rsUsers("Password") = Request.Form("password")
rsUsers("FamilyName") = Request.Form("FamilyName")
rsUsers("GivenName") = 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 ' update the database
Dim strName, strValue ' create session variables
For each strField in rsUsers.Fields
strName = strField.Name
strValue = strField.value
Session(strName) = strValue
Next
Session("blnValidUser") = True ' declare that current user is validated
Response.Redirect "MenuForRegisteredUsers.asp"
%>
checklogin:
<%
Dim strEMail, strPassword
strEMail = Request("EMail")
strPassword = Request("Password")
Dim rsUsers
set rsUsers = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Person WHERE EMailAddress = '" & strEMail & "';"
rsUsers.Open strSQL, objConn
If rsUsers.EOF Then ' User not found
Session("EMailAddress") = Request("EMail")
If Request("SecondTry") = "True" then ' User's had two goes
Response.Redirect "register.asp?NotFound=True" ' - must register
Else ' Username wrong; password wrong
Response.Redirect "login.asp?SecondTry=True" ' - allow another go
End If
Else 'One or more users found - check password
While Not rsUsers.EOF
If UCase(rsUsers("Password")) = UCase(strPassword) Then ' password matched
Dim strName, strValue
For Each strField in rsUsers.Fields
strName = strField.Name ' populate session variables
strValue = strField.value
Session(strName) = strValue
Next
Session("blnValidUser") = True
Response.Redirect "MenuForRegisteredUsers.asp" ' successful login
Else
rsUsers.MoveNext
End If
Wend
Session("EMailAddress") = Request("EMail") ' if we get this far then...
' ...password doesn't match any of DB entries
If Request("SecondTry") = "True" then ' User's had two goes
Response.Redirect "register.asp" ' - must reregister
Else ' Username right; password wrong
Response.Redirect "login.asp?SecondTry=True&WrongPW=True"
'- allow another go
End If
End If
%>
clssfd:
<!-- METADATA TYPE="typelib"
FILE="c:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= D:\Inetpub\wwwroot\begaspfiles\Classified.mdb"
If Session("blnValidUser") = True and Session("PersonID") = "" Then
Dim rsPersonIDCheck
Set rsPersonIDCheck = Server.CreateObject("ADODB.Recordset")
Dim strSQL
strSQL = "SELECT PersonID FROM Person " & _
"WHERE EMailAddress = '" & Session("EMailAddress") & "';"
rsPersonIDCheck.Open strSQL, objConn
If rsPersonIDCheck.EOF Then
Session("blnValidUser") = False
Else
Session("PersonID") = rsPersonIDCheck("PersonID")
End If
rsPersonIDCheck.Close
Set rsPersonIDCheck = Nothing
End If
%>
Please Help me:
|