variables being held in memory?
Posted: Tue Aug 26, 2003 2:06 pm
Well, this'll be my first post here, and hopefully it's not a total disaster. Sorry, but I'm not exactly sure how to quickly describe this problem.
I'm building a shopping cart app. All items in your shopping cart are stored as an associative array (Item number => quantity). There's a nice big fat REMOVE button next to any item in your shopping cart... if you click it POSTS back to the same page with a hidden field where $Remove = the ItemNo to be removed. The page switches to detect if Remove is set, and if it is, it unsets that variable from the array. Works just fine.
But here's the problem. Apparently somewhere, somehow, the most recently posted variables are being cached, because when you reload the page, it sends it all again and will increment the quantity of whatever item you last posted. This is not desireable from a page refresh. Likewise, if you Remove an item and then Remove a different item, the first item you removed shows right back up again! You can play a fun little see-saw game by clicking the Remove button all day and watching the items switch back and forth! So what I imagine is happening is that somehow the most recent POST variables are being stored and applied again whenever you make a page change. But why, and how do I stop it?
So. Does anyone know why this problem is happening? I figure this is probably a pretty simple theoretical question, and so I'd rather not post excessive amounts of code just yet. Any ideas?
I'm building a shopping cart app. All items in your shopping cart are stored as an associative array (Item number => quantity). There's a nice big fat REMOVE button next to any item in your shopping cart... if you click it POSTS back to the same page with a hidden field where $Remove = the ItemNo to be removed. The page switches to detect if Remove is set, and if it is, it unsets that variable from the array. Works just fine.
But here's the problem. Apparently somewhere, somehow, the most recently posted variables are being cached, because when you reload the page, it sends it all again and will increment the quantity of whatever item you last posted. This is not desireable from a page refresh. Likewise, if you Remove an item and then Remove a different item, the first item you removed shows right back up again! You can play a fun little see-saw game by clicking the Remove button all day and watching the items switch back and forth! So what I imagine is happening is that somehow the most recent POST variables are being stored and applied again whenever you make a page change. But why, and how do I stop it?
So. Does anyone know why this problem is happening? I figure this is probably a pretty simple theoretical question, and so I'd rather not post excessive amounts of code just yet. Any ideas?