Wrox Programmer Forums
|
Classic ASP Components Discussions specific to components in ASP 3.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Components 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 April 2nd, 2008, 02:26 PM
Registered User
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing session variables from login page.

I am trying to pass session variables from login page but I am getting an error. Can anyone help why?

My default page code is

Code:
<%
'-- Simple function to replace single quotes --
Function ValidateStr(strValue)
    strTemp = strValue
    strTemp = Trim(strTemp)
    strTemp = Replace(strTemp,"'","''")
    ValidateStr = strTemp
End Function


'-- Check that form has been submitted --
If Request.Form("Submit") = "Login" Then
    '-- Grab form values --
    UserEmail = ValidateStr(Request.Form("UserEmail"))
    UserPassword = ValidateStr(Request.Form("UserPassword"))


    ' -- Check if both email and password were submitted -
    If UserEmail = "" OR UserPassword = "" Then
        strError = "You must enter both an email address and password."
    End If


    ' -- If no errors, continue --
    If strError = "" Then
        '-- Connect to DB and create recordset --
        Set conn = Server.CreateObject("ADODB.Connection")
        conn.Provider = "Microsoft.Jet.OLEDB.4.0"
        conn.Open Server.MapPath("login.mdb")
        Set rsLogin = Server.CreateObject("ADODB.recordset")


        '-- Select the data from the DB using the submitted information --
        strSQL = "SELECT UserID, UserEmail, UserPassword FROM tblUsers WHERE UserEmail = '" & UserEmail & "' AND UserPassword = '" & UserPassword & "'"
        rsLogin.Open strSQL, conn


        ' -- Check that user exists --
        If Not rsLogin.EOF Then
            '-- If match found, and user exists, then set session variable --
            Session("UserID") = rsLogin("UserID")
            ' -- Redirect to protected page --
            Response.Redirect "profile.asp"
        Else
            strError = "Login failed."
        End If
    End If
End If
%>

<b><%= strError %></b><p />&nbsp;&nbsp;&nbsp;&nbsp;

<form name="login" method="post" action="default.asp">
  <table width="400" border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td>Email Address</td>
      <td><input name="UserEmail" type="text" value="<%= UserEmail %>" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input name="UserPassword" type="password" value="<%= UserPassword %>" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Login" /></td>
    </tr>
  </table>
</form>

My profile page code is

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
Set conn = Server.CreateObject("ADODB.Connection")
        conn.Provider = "Microsoft.Jet.OLEDB.4.0"
        conn.Open Server.MapPath("login.mdb")

UserID = Session("UserID")
response.write "User ID: " & UserID
'response.end
strSQL = "SELECT UserName FROM tblUsers WHERE UserID = " & UserID
Set loginRS = Conn.Execute(strSQL)

strUserName = loginRS("UserName")

response.write "Welcome " & strUserName & " to the password protected portion of my site."
%>
<p>profile happy </p>
<p>&nbsp; </p>
</body>
</html>
The error I am getting is Microsoft Jet Database Engine (0x80040E14)
Syntax error (missing operator) in query expression 'UserID='./profile.asp, line 18


Please help.





 
Old April 23rd, 2008, 11:54 PM
Authorized User
 
Join Date: Sep 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prabodh_mishra
Default

Check if you have EnableSessionState On and rsLogin("UserID") is actually returning anything.



Prabodh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variables with Login jflores1 Beginning PHP 2 January 10th, 2006 09:27 AM
Passing Session Variables to the Next Page [email protected] ASP.NET 1.0 and 1.1 Professional 1 August 1st, 2004 06:25 PM
Passing Session Variables to the Next Page [email protected] Classic ASP Databases 2 August 1st, 2004 01:59 PM
login page and session variables scdownload Classic ASP Basics 0 December 8th, 2003 06:13 PM





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