User information won't show up in account page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jerrydigital
    New Member
    • Oct 2008
    • 67

    User information won't show up in account page

    Hello, I am having trouble getting unique user information on my account page. Currently, once the user logs in, it will only display "Welcome...(the n the same name pops up no matter who logs in)".

    After the login.html page, the form redirects the user to the loggedin.asp page which verifies the users email and password are in the database. Here's the loggedin.asp code:


    loggedin.asp:
    Code:
    <%@ Language=VBScript %>
    <% Option Explicit %>
    <!--#include virtual="/adovbs.inc"-->
    
    <%
    
    Dim oConn
    Dim connectstr, sDSNDir, tablename
    Dim db_name, db_username, db_userpassword
    Dim dsn_name
    
    dsn_name = "access_table.dsn"
    tablename = "tblRegister"
    db_username = "$$$$$"
    db_userpassword = "$$$$"
    
    sDSNDir = Server.MapPath("/_dsn")
    connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open connectstr
    
    Dim objRS, bolFound, strEmail
    strEmail = Request.Form("email")
    
    If strEmail = "" Then
    oConn.Close
    Set oConn = Nothing
    Response.Write "<a href='login.html'>"
    Response.Write "You must enter a email address"
    Response.Write "</a>"
    Response.End
    End If
    
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open "tblRegister", oConn, , , adCmdTable
    bolFound = False
    
    Do While Not (objRS.EOF OR bolFound)
    If (StrComp(objRS("Email"), strEmail, vbTextCompare) = 0) Then
    BolFound = True
    Else
    objRS.MoveNext
    End If
    Loop
    
    If Not bolFound Then
    objRS.Close
    Set objRS = Nothing
    oConn.Close
    Set oConn = Nothing
    Response.Write "<a href='login.html'>"
    Response.Write "Invalid Email Address.<p>"
    Response.Write "</a>"
    Response.End
    End If
    
    If Not (StrComp(objRS("Password"), Request.Form("password"), _
    vbBinaryCompare) = 0) Then
    objRS.Close
    Set objRS = Nothing
    oConn.Close
    Set oConn = Nothing
    Response.Write "<a href='login.html'>"
    Response.Write "Invalid password.<p>"
    Response.Write "</a>"
    Response.End
    Else
    session("email") = objRS("email")
    Response.Redirect("accountpage.asp")
    Response.End
    End If
    
    objRS.Close
    Set objRS = Nothing
    oConn.Close
    Set oConn = Nothing
    %>
    This page verifies the user information and then loads the accountpage.asp . The code is:

    accountpage.asp
    Code:
    <%@ Language=VBScript %>
    <% Option Explicit %>
    <!--#include virtual="/adovbs.inc"-->
    
    <%
    If session("email") = "" Then
        Response.Redirect "login.html"
        Response.End
    Else
    	Response.Write "You are logged in as " & session("email") & "<br>"
    End If
    
    Dim oConn
    Dim connectstr, sDSNDir, tablename
    Dim db_name, db_username, db_userpassword
    Dim dsn_name
    
    dsn_name = "access_table.dsn"
    tablename = "tblRegister"
    db_username = "$$$$"
    db_userpassword = "$$$$$"
    
    sDSNDir = Server.MapPath("/_dsn")
    connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
    
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open connectstr
    
    Dim objRS
    
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open "tblRegister", oConn, , , adCmdTable
    %>
    
    <html>
    <head><title>Account Page</title></head>
    <h1>
    <b><font face="castellar">Welcome <%=objRS("FirstName" )%><%=objRS("LastName")%></font></b></center></h1>
    
    </body>
    </html>
    <%
    objRS.Close
    Set objRS = Nothing
    oConn.Close
    Set oConn = Nothing
    %>
    The problem is, it doesn't matter who logs in. When the accountpage.asp loads, it always says "Welcome .....(and the name always comes up as the name of the first user in the access database, not the user logged in).

    Any ideas why this is occurring? Thank you
  • jerrydigital
    New Member
    • Oct 2008
    • 67

    #2
    I figured out my problem. I had to query the database. I put the following code in:

    Code:
    Dim strSQL, strEmail
    Dim bolFound
    
    strEmail = session("email")
    
    strSQL = "SELECT * From tblRegister"
    
    Dim objRS
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open strSQL, oConn
    bolFound = False
    
    Do While Not (objRS.EOF OR bolFound)
    If (StrComp(objRS("Email"),strEmail, vbTextCompare) = 0) Then
    BolFound = True
    Else
    objRS.MoveNext
    End If
    Loop
    
    If Not bolFound Then
    objRS.Close
    Set objRS = Nothing
    oConn.Close
    Set oConn = Nothing
    Response.Write "<a href='login.html'>"
    Response.Write "Invalid Email Address.<p>"
    Response.Write "</a>"
    Response.End
    End If
    I put this code in right after:

    Code:
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open connectstr
    And it works. Thanks to everyone at this forum. You have allowed me to successfully create my first website.

    Jerry

    Comment

    Working...