navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

UserName Session variable

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> UserName Session variable
Page: [1]
 
cahigg

 

Posts: 6
From: None
Status: offline

 
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
%>

Spooky

 

Posts: 26603
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: UserName Session variable - 7/25/2001 20:52:00   
As username is text, youll need to ensure its enclosed in quotes :

strSQL = strSQL & "WHERE UserName = '" & strLoggedInUsername & "'"

------------------
§þððk¥
"I am Spooky of Borg. Prepare to be assimilated, babycakes!"
Subscribe to OutFront News
Database / DRW Q & A
The Spooky Login!
VP-ASP Shopping cart


(in reply to cahigg)
cahigg

 

Posts: 6
From: None
Status: offline

 
RE: UserName Session variable - 7/25/2001 20:04:00   
When oh when will I learn to check the syntax more carefully. Thanks Spooky. If I have any more typos, I'll be sure to post them here.

Thanks again,
Chris


(in reply to cahigg)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> UserName Session variable
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts