Connecting Tech Pros Worldwide Help | Site Map

User information won't show up in account page

Member
 
Join Date: Oct 2008
Location: Cleveland Ohio
Posts: 67
#1: Nov 14 '08
Hello, I am having trouble getting unique user information on my account page. Currently, once the user logs in, it will only display "Welcome...(then 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:
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <!--#include virtual="/adovbs.inc"-->
  4.  
  5. <%
  6.  
  7. Dim oConn
  8. Dim connectstr, sDSNDir, tablename
  9. Dim db_name, db_username, db_userpassword
  10. Dim dsn_name
  11.  
  12. dsn_name = "access_table.dsn"
  13. tablename = "tblRegister"
  14. db_username = "$$$$$"
  15. db_userpassword = "$$$$"
  16.  
  17. sDSNDir = Server.MapPath("/_dsn")
  18. connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
  19.  
  20. Set oConn = Server.CreateObject("ADODB.Connection")
  21. oConn.Open connectstr
  22.  
  23. Dim objRS, bolFound, strEmail
  24. strEmail = Request.Form("email")
  25.  
  26. If strEmail = "" Then
  27. oConn.Close
  28. Set oConn = Nothing
  29. Response.Write "<a href='login.html'>"
  30. Response.Write "You must enter a email address"
  31. Response.Write "</a>"
  32. Response.End
  33. End If
  34.  
  35. Set objRS = Server.CreateObject("ADODB.Recordset")
  36. objRS.Open "tblRegister", oConn, , , adCmdTable
  37. bolFound = False
  38.  
  39. Do While Not (objRS.EOF OR bolFound)
  40. If (StrComp(objRS("Email"), strEmail, vbTextCompare) = 0) Then
  41. BolFound = True
  42. Else
  43. objRS.MoveNext
  44. End If
  45. Loop
  46.  
  47. If Not bolFound Then
  48. objRS.Close
  49. Set objRS = Nothing
  50. oConn.Close
  51. Set oConn = Nothing
  52. Response.Write "<a href='login.html'>"
  53. Response.Write "Invalid Email Address.<p>"
  54. Response.Write "</a>"
  55. Response.End
  56. End If
  57.  
  58. If Not (StrComp(objRS("Password"), Request.Form("password"), _
  59. vbBinaryCompare) = 0) Then
  60. objRS.Close
  61. Set objRS = Nothing
  62. oConn.Close
  63. Set oConn = Nothing
  64. Response.Write "<a href='login.html'>"
  65. Response.Write "Invalid password.<p>"
  66. Response.Write "</a>"
  67. Response.End
  68. Else
  69. session("email") = objRS("email")
  70. Response.Redirect("accountpage.asp")
  71. Response.End
  72. End If
  73.  
  74. objRS.Close
  75. Set objRS = Nothing
  76. oConn.Close
  77. Set oConn = Nothing
  78. %>
This page verifies the user information and then loads the accountpage.asp. The code is:

accountpage.asp
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <!--#include virtual="/adovbs.inc"-->
  4.  
  5. <%
  6. If session("email") = "" Then
  7.     Response.Redirect "login.html"
  8.     Response.End
  9. Else
  10.     Response.Write "You are logged in as " & session("email") & "<br>"
  11. End If
  12.  
  13. Dim oConn
  14. Dim connectstr, sDSNDir, tablename
  15. Dim db_name, db_username, db_userpassword
  16. Dim dsn_name
  17.  
  18. dsn_name = "access_table.dsn"
  19. tablename = "tblRegister"
  20. db_username = "$$$$"
  21. db_userpassword = "$$$$$"
  22.  
  23. sDSNDir = Server.MapPath("/_dsn")
  24. connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
  25.  
  26. Set oConn = Server.CreateObject("ADODB.Connection")
  27. oConn.Open connectstr
  28.  
  29. Dim objRS
  30.  
  31. Set objRS = Server.CreateObject("ADODB.Recordset")
  32. objRS.Open "tblRegister", oConn, , , adCmdTable
  33. %>
  34.  
  35. <html>
  36. <head><title>Account Page</title></head>
  37. <h1>
  38. <b><font face="castellar">Welcome <%=objRS("FirstName" )%><%=objRS("LastName")%></font></b></center></h1>
  39.  
  40. </body>
  41. </html>
  42. <%
  43. objRS.Close
  44. Set objRS = Nothing
  45. oConn.Close
  46. Set oConn = Nothing
  47. %>
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
Member
 
Join Date: Oct 2008
Location: Cleveland Ohio
Posts: 67
#2: Nov 15 '08

re: User information won't show up in account page


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

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL, strEmail
  2. Dim bolFound
  3.  
  4. strEmail = session("email")
  5.  
  6. strSQL = "SELECT * From tblRegister"
  7.  
  8. Dim objRS
  9. Set objRS = Server.CreateObject("ADODB.Recordset")
  10. objRS.Open strSQL, oConn
  11. bolFound = False
  12.  
  13. Do While Not (objRS.EOF OR bolFound)
  14. If (StrComp(objRS("Email"),strEmail, vbTextCompare) = 0) Then
  15. BolFound = True
  16. Else
  17. objRS.MoveNext
  18. End If
  19. Loop
  20.  
  21. If Not bolFound Then
  22. objRS.Close
  23. Set objRS = Nothing
  24. oConn.Close
  25. Set oConn = Nothing
  26. Response.Write "<a href='login.html'>"
  27. Response.Write "Invalid Email Address.<p>"
  28. Response.Write "</a>"
  29. Response.End
  30. End If
I put this code in right after:

Expand|Select|Wrap|Line Numbers
  1. Set oConn = Server.CreateObject("ADODB.Connection")
  2. oConn.Open connectstr
And it works. Thanks to everyone at this forum. You have allowed me to successfully create my first website.

Jerry
Reply