Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2005, 06:42 AM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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">&nbsp;&nbsp;
                       <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:


 
Old March 10th, 2005, 11:05 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Do u get any error while adding data..?

Om Prakash
 
Old March 11th, 2005, 01:02 AM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply:
Yes, i am having error:
The database is updating one user at one time.
when i try to register the new user to the database, the old user gets deleted and cannot be logged in.
Please help me soon.
Thank you.

 
Old March 11th, 2005, 01:33 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

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


What is the unique Id in your table.. personID or Emailid..?


Om Prakash




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with adding rows to database gule2902 Visual Basic 2005 Basics 4 September 13th, 2007 05:10 PM
Adding Controls to User Control bmains C# 2005 0 June 5th, 2006 09:09 PM
adding new worksheet using user form sime_tyres Excel VBA 1 February 21st, 2006 12:35 AM
adding new user to the database ali786 Classic ASP Databases 1 March 21st, 2005 01:34 AM
Problem with adding user to dabase ali786 Classic ASP Databases 0 March 9th, 2005 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.