Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie Problem - Time?

Status
Not open for further replies.

pl12987

Programmer
Aug 2, 2001
53
US
I am having trouble getting a cookie to set.

I am processing an order form. From the FORM variables, I pull a query of several items checked off the order form. I want to store the query results (called "pullinfo"), row by row, in a cookie
(using CFLOOP).

The first time with the first item, my CFIF tests for a cookie, sees no cookie exists, so it sets a new one. Then it adds in the first row of the loop. Fine so far.

On the second (and subsequent passes) CFIF should see a cookie exists, and use a different CFCOOKIE block of code to add the new row to the EXISTING cookie (named "cart"), viz:

<cfoutput>
<cfcookie name = &quot;cart&quot; value = &quot;#cookie.cart# #quantity#, #pullinfo.itemid#, #pullinfo.item#, #pullinfo.title#, #pullinfo.spec1#, #pullinfo.spec2#, #pullinfo.spec3#, #pullinfo.spec4#;&quot; expires = &quot;1&quot;>
</cfoutput>
<!---Note that in adding the new item to the existing cookie, we put no punctuation after cookie.cart because the semicolon we need is already contained inside it. If you add a comma or semicolon here, it will be a DOUBLE and a blank space will be defined as an item.--->

(end of code snippet)

That's my second-pass CFCOOKIE.

Now, the first pass is going through fine, but not the second. What I see is the first pass, along with my watch flag that tells me CFIF saw no cookie. But I also see my debug flag &quot;END OF PASS TWO&quot; which means it DID cycle all the way through. But the second item never got there.

My theory: Could this be a time issue? The only thing I can think of is that the initial cookie just has not finished setting by the time CFLOOP delivers the second row. So CFIF never sees a cookie, and the cookie is overwritten with the first row all over again. Is that possible? Can anybody think of another reason why the second row never gets in? What do YOU do with dumping in multiple rows to a cookie?



 
Are you setting the first cookie and then checking for it on the same page? If so, I don't think that will work -- you would have to check for it on a different page than the page you are setting the first cookie on.
 
The cookie gets written by the WEB server (and NOT the CF server), and thus, after the page is completely rendered in HTML. That's why cookies don't get written on pages you leave via CFLOCATION. Similar problem here: the cookie will not be written until CF is done with the page and completely rendered it in HTML.

So my suggestion is to build up the cookie value completely in a variable. Use the variable in your code until you're ready to leave the page, then write out the cookie.
 

Thanks much! I was trying to do too much at once with the cookie. It's much easier to loop and set a variable and then set the cookie at the end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top