472,783 Members | 921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

Refresh problem - last command gets re-executed - how to prevent?

Hi there,

Working on the PHP DB I took over I have just come across a problem. When
the user presses refresh in some circumstances the command they just
performed will be re-performed. In some cases this is very undesirable.

Further example:

There is a PHP page in my web application that has a text box and the
ability to add a note to the account the user is currently viewing. When the
user presses submit the page reposts to itself with a hidden command
parameter so the form knows what to do before redisplaying the account
details (with the new note).
However if the user presses refresh, the command gets re-executed again and
we now have another identical note added to the account.

Not desirable behaviour particularly when it comes to editing / deleting
items etc.

Bearing in mind this is a large application that will have many pages to
change and a Monday deadline for new changes, what is an easy way I can
prevent this? How do other people cope with this? Maybe from the start the
whole thing should have been approached differently but I have to work with
what I have.

Any suggestions?


Jul 17 '05 #1
3 3528
Dave Smithz wrote:
Hi there,

Working on the PHP DB I took over I have just come across a problem. When
the user presses refresh in some circumstances the command they just
performed will be re-performed. In some cases this is very undesirable.

....snip...
Any suggestions?


One solution which would be a quick and reasonable fix, would be to add
something like the following two lines, right after the DB updates...

header("Location: " . $_SERVER["SCRIPT_NAME"]);
exit();

This redirects the browser back to the current page, clearing all of the
form vars. Might not be exactly what you want though - for one, it does
not take account of vars that might be tacked onto the url, so you'll
want to deal with that as appropriate...
Jul 17 '05 #2
I ran into the same problem. Just letting the the script fall thru and
display a new page invites problems. I ended up having the script
redirect back to itself after making sure everything was cleaned up.
That way if the user manually refreshes a page, that's all they get, no
duplicate operations.

The other thing I've used on some projects is to have a centralized PHP
page to process database operations. It redirects back to the parent
page when it's done. Each calling page would have a hidden input value
that the db page keys on so it knows what to do.

Both of them work like a charm.
Daniel

Jul 17 '05 #3
Dave Smithz wrote:
Hi there,

Working on the PHP DB I took over I have just come across a problem. When
the user presses refresh in some circumstances the command they just
performed will be re-performed. In some cases this is very undesirable.

Further example:

There is a PHP page in my web application that has a text box and the
ability to add a note to the account the user is currently viewing. When the
user presses submit the page reposts to itself with a hidden command
parameter so the form knows what to do before redisplaying the account
details (with the new note).
However if the user presses refresh, the command gets re-executed again and
we now have another identical note added to the account.

Not desirable behaviour particularly when it comes to editing / deleting
items etc.

Bearing in mind this is a large application that will have many pages to
change and a Monday deadline for new changes, what is an easy way I can
prevent this? How do other people cope with this? Maybe from the start the
whole thing should have been approached differently but I have to work with
what I have.

Any suggestions?


i have a hidden field on all forms identifying the form:

<input name="formID" type="hidden" value="<?= time() ;?>">

when an insert is performed, the 'formID' is inserted into a database
table called 'formIDs'.

an insert can only be performed if the formID is not already in the , i
check that the formID is not already in the table 'formIDs'.

if you refresh, the formID does not change, so there will be no insert
performed.

it is *extrememly* unlikely that two forms will have the same 'formID' -
but not absolutely impossible.

sadara

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Scott | last post by:
I have a clickable graph that resides on page 1. If user clicks a data point on the graph, the page runs again yeilding a 2nd graph that shows a more detailed graph. Problem is, I have a...
5
by: Steve | last post by:
Hi, I have a private website for 20 people that is similar to a web email client like hotmail. There are two frames, one on the left with links for "New", "History", "Todays" and a frame on the...
3
by: Dag Sunde | last post by:
Is there a way to detect if the reason an onUnload() handler was called originated from the user explicitly refreshed the page(s)? Ie. pressed "Ctrl-R", "F5" or klicked the refresh button in...
0
by: thomasp | last post by:
This is a two part question, 1) The code below should display a form with a datagridview and a few command buttons. This form should allow the user to make change to the records displayed in...
3
by: Guru | last post by:
How do I refresh GridView using CallBack? I am populating the grid at runtime using OLEDB.
1
by: Areric | last post by:
Hey all, Does anyone know how i can detect a refresh of the page in the unload event on the server? The problem I'm having is that refresh automatically calls the previous event that happened...
0
by: M G Henry | last post by:
I am using Access 2003 and have a form with two subforms on them. I would like to be able to use a command button to add the row of data ( 5 fields ) that are completed on the subform, as well as...
6
by: Chris Larmer | last post by:
I have two subforms in my main form. In the main form I want the user to select a customer, class, and date range. The 2 subforms are similar. One is the history records in the recent past and the...
7
by: keyser soze | last post by:
hi i have a stored proc, pointed by a synonym i wish to execute it vía: cmd.commandType= adStoredProc cmd.commandText= "s_MyStoredProc" cmd.parameters.refresh ---to get the collection the...
2
by: philbo30 | last post by:
I have data processing that takes place via an application written in C. I also have a .php webpage that displays a chart of the results via the Netscape 4.79 browser. Currently, manual...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.