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

01-27-04, 16:47
|
|
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?
|
|

01-27-04, 17:20
|
|
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).
|
|

01-28-04, 06:27
|
|
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?
|
|
|

01-29-04, 06:02
|
|
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
%>
|
|

01-29-04, 22:52
|
|
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
----------------------------------------------------------------
|
|

01-29-04, 23:16
|
|
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?
|
|

01-30-04, 11:11
|
|
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??
|
|

01-30-04, 11:17
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 454
|
|
What does "that does not have a value in the database" mean? Null or blank value?
|
|

01-30-04, 11:29
|
|
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?
|
|
|

01-30-04, 12:04
|
|
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.
|
|

01-31-04, 07:02
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 27
|
|
Sorry, I'm a beginner to ASP. Any hints on how to do this?
Thanks
|
|

01-31-04, 07:55
|
|
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?
|
|

01-31-04, 15:43
|
|
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.
|
|

02-02-04, 05:00
|
|
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.
|
|
|

02-03-04, 11:02
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 454
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|