Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jan 2004
    Posts
    27

    Unanswered: 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?

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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).

  3. #3
    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.




    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?

  4. #4
    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
    
    %>

  5. #5
    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



    ----------------------------------------------------------------

  6. #6
    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?

  7. #7
    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??

  8. #8
    Join Date
    Dec 2003
    Posts
    454
    What does "that does not have a value in the database" mean? Null or blank value?

  9. #9
    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.

    Originally posted by gyuan
    What does "that does not have a value in the database" mean? Null or blank value?

  10. #10
    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.

  11. #11
    Join Date
    Jan 2004
    Posts
    27
    Sorry, I'm a beginner to ASP. Any hints on how to do this?
    Thanks

  12. #12
    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?

  13. #13
    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.

  14. #14
    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.

    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.

  15. #15
    Join Date
    Dec 2003
    Posts
    454
    This is one of the references from Microsoft web site.

    http://www.microsoft.com/windows2000...p/vbob12d0.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •