/    Sign up×
Community /Pin to ProfileBookmark

How to stop updating SQL again on page refresh?

Hi, how can i stop a mysql update query re-running every time i refresh a page? I want it to run once and that’s it. I tried using a variable and if statement to only run once but this didn’t work. Is there a way to redirect page and not update when the refresh button is pressed?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 12.2006 — If you're using session control, then you could set a $_SESSION value upon completion of the query, and add an if clause that only does the query if that session value is not set or is not set to that value.
Copy linkTweet thisAlerts:
@mcpalmerauthorMar 12.2006 — I'm not but i thinks that what i should do, i'll try it out.
Copy linkTweet thisAlerts:
@mcpalmerauthorMar 13.2006 — I tried this set up:

first page creates session variable called sqlupdated - its a boolean and set to false. A link to a new page sends a url variable, testvar ( tested against to ensure someone going direct to update page does not trigger update ). this page has following php:


[CODE]if($_SESSION['sqlupdated']==false&&$testvar){

print("updated sql");
$_SESSION['sqlupdated']=true;
} else {

print("sql NOT updated");
}[/CODE]


By my logic, when you initally go to the new page, sqlupdated will be false, as set in previous page, and testvar will exist cos it sent from previous page so the if statement is run, and this is exactly what happens. However, when i refresh the page, the if statement still runs, whereas i thought it would be the else because i have set sqlupdated to true. What am i doing wrong here?
Copy linkTweet thisAlerts:
@mcpalmerauthorMar 13.2006 — Fixed, i wasn't renewing the session when i went to the new page. Anyway, I found a non-sessions approach to use in the end and decided to go with that, cheers
×

Success!

Help @mcpalmer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...