tags:

views:

52

answers:

1

When a vote value is changed, the form POSTs the change, then refreshes the page. This is called on the top of the page upon load:

  if (isset($_POST['q'.$question_id]))
    {
    $user->updateQuestionVotes($question_id, $_POST['q'.$question_id]);
    }

Why does it update every time I refresh after the first time? Do I need to unset it somehow?

+5  A: 

Because that's the natural behavior of every browser. You need to redirect the user to the same page so that the POST values will not be in the header anymore.

Have you tried this?

header("Location: /back/to/same/page");

This will redirect the user to whatever page they need to land back on, removing any POST parameters that they sent. Any time you refresh a page, it uses the same headers as before, which means the POST content will still be there.

animuson
and http://en.wikipedia.org/wiki/Post/Redirect/Get as an significant addition
zerkms
THE standard IMO indeed. Although the POST values are in the body of the request, not the header :)
Wrikken
Can I return it to null after I get the information I need from it?
Cortopasta
There's no need to unset anything. Once you redirect the page after you store whatever, the POST information will no longer exist anyways. Without redirecting the page, there's no way for the information to be cleared because it is sent by the client's browser, so it will continue to exist until the client is directed to a new page.
animuson