473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 3570
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.