UserName Session variable - 7/24/2001 23:37:00
I am trying to integrate an asp forum script into the spooky login database. The following code gives me an error (entire code included at end):'Read in users ID number from the cookie 'lngLoggedInUserID = CLng(Request.Cookies("Forum")("UserID") / 888888) strLoggedInUsername = Session("UserName") 'If a cookie exsists on the users system then read in there username from the database If NOT strLoggedInUsername = "" Then
'Intialise the ADO recordset object Set rsLoggedInUser = Server.CreateObject("ADODB.Recordset") 'Read the various forums from the database 'Initalise the strSQL variable with an SQL statement to query the database strSQL = "SELECT Users.UserID " strSQL = strSQL & "FROM Users " strSQL = strSQL & "WHERE UserName = " & strLoggedInUsername 'Query the database rsLoggedInUser.Open strSQL, strCon 'If there is a user with the ID number read in from the cookie then If NOT rsLoggedInUser.EOF Then 'Read in the username from the recordset lngLoggedInUserID = Server.HTMLEncode(rsLoggedInUser("UserID")) 'Otherwise the username is not correct or the user has been barred so set there User ID to 0 Else lngLoggedInUserID = 0 End If End If If I use a valid Username from the Users table instead of the strLoggedInUsername in the following line the script works fine, so I'm assuming there is a problem with the strLoggedInUsername=Session("UserName") line. strSQL = "SELECT Users.UserID " strSQL = strSQL & "FROM Users " strSQL = strSQL & "WHERE UserName = " & strLoggedInUsername strLoggedInUsername apparently has a value because the following line gives me the error rsLoggedInUser.Open strSQL, strCon (too few parameters) Any help would be appreciated. Here is the entire code: <% Dim adoCon 'Database Connection Variable Dim strAccessDB 'Holds the Access Database Name Dim rsLoggedInUser 'Hols the recordset for the user Id number Dim rsConfiguration 'Holds the configuartion recordset Dim strCon 'Holds the Database driver and the path and name of the database Dim strSQL 'Holds the SQL query for the database Dim lngLoggedInUserID 'Holds a logged in users ID number Dim strLoggedInUsername 'Holds a logged in users username Dim strWebsiteName 'Holds the website name Dim strForumPath 'Holds the virtual path to the forum Dim strBgColour 'Holds the background colour of the forum Dim strTextColour 'Holds the text colour of the forum Dim strLinkColour 'Holds the link colour of the forum Dim strTableColour 'Holds the table colour Dim strTableBorderColour 'Holds the table border colour Dim strTableTitleColour 'Holds the table title colour Dim strVisitedLinkColour 'Holds the visited link colour of the forum Dim strActiveLinkColour 'Holds the active link colour of the forum Dim strForumEmailAddress 'Holds the forum e-mail address Dim blnEmail 'Boolean set to true if e-mail is on Dim blnAdminEmail 'Boolean set to true if admin e-mail is on 'Initialise variables blnEmail = False blnAdminEmail = False 'Create database connection 'Initialise the strAccessDB variable with the name of the Access Database strAccessDB = "spooky_login2000.mdb" 'Create a connection odject Set adoCon = Server.CreateObject("ADODB.Connection") '------------- If you are having problems with the script then try using a diffrent driver or DSN by editing the lines below -------------- 'Database connection info and driver (if this driver does not work then comment it out and use one of the alternative drivers) strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\inetpub\wwwroot\nmcg.org\db\spooky_login2000.mdb" 'Alternative drivers faster than the basic one above 'strCon = "Provider=Microsoft.Jet.OLEDB.3.51; Data Source=" & Server.MapPath(strAccessDB) 'This one is if you convert the database to Access 97 'strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(strAccessDB) 'This one is for Access 2000
'If you wish to use DSN then comment out the driver above and uncomment the line below (DSN is slower than the above drivers) 'strCon = "DSN=forum" 'Place the DSN name after the DSN= '--------------------------------------------------------------------------------------------------------------------------------------------- 'Set an active connection to the Connection object adoCon.Open strCon
'Read in the Forum configuration 'Intialise the ADO recordset object Set rsConfiguration = Server.CreateObject("ADODB.Recordset") 'Initialise the SQL variable with an SQL statement to get the configuration details from the database strSQL = "SELECT tblConfiguration.* From tblConfiguration;" 'Query the database rsConfiguration.Open strSQL, strCon 'If there is config deatils in the recordset then read them in If NOT rsConfiguration.EOF Then 'read in the configuration details from the recordset strWebsiteName = rsConfiguration("website_name") strForumPath = rsConfiguration("forum_path") strBgColour = rsConfiguration("bg_colour") strTextColour = rsConfiguration("text_colour") strLinkColour = rsConfiguration("links_colour") strTableColour = rsConfiguration("table_colour") strTableBorderColour = rsConfiguration("table_border_colour") strTableTitleColour = rsConfiguration("table_title_colour") strVisitedLinkColour = rsConfiguration("visited_links_colour") strActiveLinkColour = rsConfiguration("active_links_colour") strForumEmailAddress = rsConfiguration("forum_email_address") blnEmail = CBool(rsConfiguration("email_notify")) blnAdminEmail = CBool(rsConfiguration("email_admin")) End If 'Read in users ID number from the cookie 'lngLoggedInUserID = CLng(Request.Cookies("Forum")("UserID") / 888888) strLoggedInUsername = Session("UserName") 'If a cookie exsists on the users system then read in there username from the database If NOT strLoggedInUsername = "" Then
'Intialise the ADO recordset object Set rsLoggedInUser = Server.CreateObject("ADODB.Recordset") 'Read the various forums from the database 'Initalise the strSQL variable with an SQL statement to query the database strSQL = "SELECT Users.UserID " strSQL = strSQL & "FROM Users " strSQL = strSQL & "WHERE UserName = " & strLoggedInUsername 'Query the database rsLoggedInUser.Open strSQL, strCon 'If there is a user with the ID number read in from the cookie then If NOT rsLoggedInUser.EOF Then 'Read in the username from the recordset lngLoggedInUserID = Server.HTMLEncode(rsLoggedInUser("UserID")) 'Otherwise the username is not correct or the user has been barred so set there User ID to 0 Else lngLoggedInUserID = 0 End If End If %>
|