If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Assigning fields in my database to a cookie

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-04, 16:47
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
Assigning fields in my database to a cookie

I want to create the cookie when the user logs in using their email address & password. Since my application involves alot of displaying a user's data to them automatically, I want to set all these values into the cookie at the time I create it.
If the SQL statement I am using only checks the email address & password, how do I set the other values......do I need to open a 2nd sql statement?
Reply With Quote
  #2 (permalink)  
Old 01-27-04, 17:20
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Use a stored procedure. Have the first part of the stored procedure check the username and password, have the second part return the data.

If you can't use a stored proc. you will need two statements (okie, you could probably do it with one but it's probably better to use two).
Reply With Quote
  #3 (permalink)  
Old 01-28-04, 06:27
shvetak shvetak is offline
Registered User
 
Join Date: Jan 2004
Posts: 3
Re: Assigning fields in my database to a cookie

You would need to modify your existing SQL Statement to get the other values also for the user apart from checking email ID and password. If you do not want to do that then create another Stored procedure or write a SQL statement which fires only if the previous email check is valid.




Quote:
Originally posted by lklegend
I want to create the cookie when the user logs in using their email address & password. Since my application involves alot of displaying a user's data to them automatically, I want to set all these values into the cookie at the time I create it.
If the SQL statement I am using only checks the email address & password, how do I set the other values......do I need to open a 2nd sql statement?
Reply With Quote
  #4 (permalink)  
Old 01-29-04, 06:02
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
Re: Assigning fields in my database to a cookie

I tried to create a 2nd SQL statement to access the information from the other table that I want to store in the cookie. However, I am getting the following error:

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''

Code:
<%

Dim rsUsers, strSQL1
Dim strEmail, strPassword, strLoginType
	strEmail = Request.Form("txtEmail")
	strPassword = Request.Form("txtPassword")
		
	Set rsUsers = Server.CreateObject("ADODB.Recordset")
	rsUsers.CursorType = 2
	rsUsers.LockType = 3


	strSQL1 = "Select * FROM MEMBER Where EMAIL_ADDRESS = '" & strEmail & "' AND PASSWORD = '" & strPassword & "';"
	rsUsers.Open strSQL1, adoCon 

If rsUsers.EOF Then 
	Response.Redirect "2ndUserLogin.asp"
Else                                     		'One or more users found - check password
	While Not rsUsers.EOF
	   	If UCase(rsUsers("PASSWORD")) = UCase(strPassword) Then     ' password matched
			      																' successful login
			
			
			Response.Cookies("user")("firstName") = rsUsers("FIRST_NAME")
			
			Dim strSQL2, rsAccount
			Set rsUsers = Server.CreateObject("ADODB.Recordset")
			rsUsers.CursorType = 2
			rsUsers.LockType = 3

			strSQL2 = "Select * From ACCOUNT"
			rsAccount.Open strSQL2
			
			
			Response.Cookies("user")("accNo") = rsAccount("ACCOUNT_NUMBER")

			Response.Redirect "MemberMenu.asp" 
		Else 
        	rsUsers.MoveNext
      End If
    Wend
End If

	 Set adoCon = Nothing
  	 adoCon.Close

%>
Reply With Quote
  #5 (permalink)  
Old 01-29-04, 22:52
shvetak shvetak is offline
Registered User
 
Join Date: Jan 2004
Posts: 3
By the looks of your code I presume you are getting error after the following line..

-- rsAccount.Open strSQL2

Check if your rsAccount recordset returns any value. If it does, then try to retrieve the value fromthe recordset.

Do the following :
----------------------------------------------------------------
rsAccount.Open strSQL2
if not rsAccount.EOF then
Response.Cookies("user")("accNo") = rsAccount("ACCOUNT_NUMBER")

else
' do whatever you want here.
end if



----------------------------------------------------------------
Reply With Quote
  #6 (permalink)  
Old 01-29-04, 23:16
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
In your application, do you want to use the user's data after she/he is logged in? If yes, why don't you set the session variables?
Reply With Quote
  #7 (permalink)  
Old 01-30-04, 11:11
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
Ok, I have the 2nd SQL statement working now but one other problem - when I set a value into the cookie that does not have a value in the database, it causes the following error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[object]'

How do I get around this since some of my fields are optional??
Reply With Quote
  #8 (permalink)  
Old 01-30-04, 11:17
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
What does "that does not have a value in the database" mean? Null or blank value?
Reply With Quote
  #9 (permalink)  
Old 01-30-04, 11:29
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
Sorry - I mean that it is blank. For example, address has 2 fields but the user is not required to enter into both.

Quote:
Originally posted by gyuan
What does "that does not have a value in the database" mean? Null or blank value?
Reply With Quote
  #10 (permalink)  
Old 01-30-04, 12:04
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
In this case, you need to check to see if the values is a Null or blank. If it is, you need to assign a constant value or do not assign the value to the cookie.
Reply With Quote
  #11 (permalink)  
Old 01-31-04, 07:02
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
Sorry, I'm a beginner to ASP. Any hints on how to do this?
Thanks
Reply With Quote
  #12 (permalink)  
Old 01-31-04, 07:55
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
Also, I am having a problem assigning a cookie value into a textarea.
Code:
<textarea name="txtProfile" cols=30 rows=5 value ="<%Response.Write Request.Cookies("user")("Info")%>"></textarea>
Do I need to treat a textarea differently?
Reply With Quote
  #13 (permalink)  
Old 01-31-04, 15:43
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
Can you tell me why you do not want to use session variables on your application? When the user is logged on the site, her/his data can be retrieved from the table and then be assigned to the session variables. You can use the session variables to show the user's info on any page until she/he is logged out.
Reply With Quote
  #14 (permalink)  
Old 02-02-04, 05:00
lklegend lklegend is offline
Registered User
 
Join Date: Jan 2004
Posts: 27
It's not that I don't want to use them,its just that I'm not exactly sure how to! Do you just use one or the other or both together.

Quote:
Originally posted by gyuan
Can you tell me why you do not want to use session variables on your application? When the user is logged on the site, her/his data can be retrieved from the table and then be assigned to the session variables. You can use the session variables to show the user's info on any page until she/he is logged out.
Reply With Quote
  #15 (permalink)  
Old 02-03-04, 11:02
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
This is one of the references from Microsoft web site.

http://www.microsoft.com/windows2000...p/vbob12d0.htm
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On