PDA

Click to See Complete Forum and Search --> : How TO Populate Cookies


jesus4u
Feb 21st, 2001, 03:15 PM
Hello all. I need help. Here I am querying my DB and assigning the variables to the field I am joining it to.
Then I am passing the values of the variables and assigning it to the session. Then finally I am plugging in the session values into the cookie I just created.

Problem: The cookie gets created with the correct fields but not with the values passed down from the variables.

What am I doing wrong here?


If Request.Form("txtName") <> "" Then
SQL = "Select * FROM Register WHERE " & "Register.userID='" & strUserID & _
"' AND Register.password ='" & strPassword & _
"' OR Register.FirstName ='" & strFirstName & _
"' OR Register.LastName ='" & strLastName & _
"' OR Register.Address ='" & strAddress & _
"' OR Register.State ='" & strState & _
"' OR Register.ZipCode ='" & strZipCode & _
"' OR Register.PhoneNumber ='" & strPhoneNumber & _
"' OR Register.Email ='" & strEmail & "'"


cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")

RecordSet.Open cmdDC, , 3, 3

'-- If there is no record found skip this section and display current error page
If Recordset.EOF Then
Else
Session("NewUserID") = strUserID
Session("Password") = strPassword
Session("FirstName") = strFirstName
Session("LastName") = strLastName
Session("Address") = strAddress
Session("State") = strState
Session("ZipCode") = strZipCode
Session("PhoneNumber") = strPhoneNumber
Session("Email") = strEmail

Response.Cookies("ReclaimAmerica").Expires = Date+365
Response.Cookies("ReclaimAmerica").Secure = FALSE
Response.Cookies("ReclaimAmerica")("UserID") = Session("NewUserID")
Response.Cookies("ReclaimAmerica")("Password") = Session("Password")
Response.Cookies("ReclaimAmerica")("FirstName") = Session("FirstName")
Response.Cookies("ReclaimAmerica")("LastName") = Session("LastName")
Response.Cookies("ReclaimAmerica")("Address") = Session("Address")
Response.Cookies("ReclaimAmerica")("State") = Session("State")
Response.Cookies("ReclaimAmerica")("ZipCode") = Session("ZipCode")
Response.Cookies("ReclaimAmerica")("Phone") = Session("Phone")
Response.Cookies("ReclaimAmerica")("Email") = Session("Email")


Response.Clear
Response.Redirect "welcome.asp"
Response.End

jesus4u
Feb 22nd, 2001, 07:54 AM
need help please!

Jerry Grant
Feb 22nd, 2001, 08:11 AM
I don't understand the question!

If you are putting a variable into a cookie then you can do it direct:

Response.Cookies("ReclaimAmerica")("UserID") = strUserID

This would be quicker than retrieving it from the session variable first.

Secondly, why are you using session variables when the same values are in the cookie?

If you are woried about client side cookies being disabled, don't use them in the first place!
:cool:

jesus4u
Feb 22nd, 2001, 08:12 AM
Thanks for the response. What I am trying to do is retreive the users information from the database and create a cookie with that info.

jesus4u
Feb 22nd, 2001, 08:24 AM
If the user loses the cookie I have a log in page where they should just log in and then I read the database and then create a new cookie with their personalized info..

I am trying to use this code to read the DB and assign the values to the variables so I can then create a cookie with the variables:

If Request.Form("txtName") <> "" Then
SQL = "Select * FROM Register WHERE " & "Register.userID='" & strUserID & _
"' AND Register.password ='" & strPassword & _
"' OR Register.FirstName ='" & strFirstName & _
"' OR Register.LastName ='" & strLastName & _
"' OR Register.Address ='" & strAddress & _
"' OR Register.State ='" & strState & _
"' OR Register.ZipCode ='" & strZipCode & _
"' OR Register.PhoneNumber ='" & strPhoneNumber & _
"' OR Register.Email ='" & strEmail & "'"