Jump to content

Refresh issue


EchoFool

Recommended Posts

I have a problem with my script where by if a user refreshes the page the increment will keep going on a post isset check.

 

Ill explain slightly better now:

 

I have this in my form:

<input type="submit" name="Button2" value="Travel">

 

Now if a user presses it, it runs this script:

<?php
If(isset($_POST['Button2'])){
$UPDATE = mysql_query("UPDATE tblname SET Y=Y+1 WHERE UserID='{$_SESSION['Current_User']}'")
Or die(mysql_error());
}
?>

 

Now if i refresh the page after this just happens, it will still think the Button2 has been set. How ever refresh is needed (without it running the query again) for reasons to do with the games features which i don't need to go into.

 

I tried putting a

<?php unset($_POST['Button2']); ?>

in the if statement..

But that didn't work.. so hope you have some suggestions you can help me with here.

Link to comment
https://forums.phpfreaks.com/topic/98080-refresh-issue/
Share on other sites

easy way to quick fix this is via sessions

<?php
session_start();
If(isset($_POST['Button2']) && !isset($_SESSION['submitted'])){
$UPDATE = mysql_query("UPDATE tblname SET Y=Y+1 WHERE UserID='{$_SESSION['Current_User']}'")
Or die(mysql_error());
$_SESSION['submitted'] = 1;
}
?>

Just make sure you kill the session if they try and do a valid resubmit.

Link to comment
https://forums.phpfreaks.com/topic/98080-refresh-issue/#findComment-501810
Share on other sites

Yeh but if the user then presses the button to move up another Y co-ordinate .. the session will still be set and so the query won't happen.

Ideally i want the script to only change when the button is pressed and not when the page is refreshed. Thats as simple as i can get with explaining.

Link to comment
https://forums.phpfreaks.com/topic/98080-refresh-issue/#findComment-501811
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.