I have a major issue and don't really know how to get around it.
What I am trying to do is this:
A user selects a value from a drop down list and then enters a quantity in a text field and then press an add button. The result is then transferred into a textarea box in the format of
'item xxxx (2)' without the quotes.
At the same time this happens a DB search is done to find out how many points a certain item is worth and is then added to a session variable. Many items can be added to to the textarea and thusly increasing the value of the session variable.
Then I can submit the form that updates my DB with the items and quantities and the total number of points accumulated (session variable)
All the above stuff works great, however I recently found out that if I click the refresh button or hit F5 before i submit the form, the session variable increments by the value of the last points value.
This is obviously unwanted and I need to know how I can achieve this with PHP prefferably, but am willing to try some javascript.
SESSION value increases when browser is reloaded
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
you could potentially use another session var to detech whether or not to increment the value
You must make sure you delete the session when you are viewing different products though.
Code: Select all
if ($_SESSION['checked'])
{
//do the calcs
}
else
{
//use your previously done calcs
}
$_SESSION['checked'] = isset($_SESSION['checked']) ? $_SESSION['checked'] : TRUE;- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
unset($_SESSION['checked']);OK, I just realized that I already use that at the submission part of my script, and that works.
But I can't really use that in the middle of the script as I use the value of the Session Variable to update the variable again when another item is added.
I hope I am explaing myself correctly.
Here is how I currently populate the Session variable:
But I can't really use that in the middle of the script as I use the value of the Session Variable to update the variable again when another item is added.
I hope I am explaing myself correctly.
Here is how I currently populate the Session variable:
Code: Select all
$_SESSION['points'] = (($x_pts['points'])*($_POST['spkrs_txt'])) + $_SESSION['points'];