473,324 Members | 2,239 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,324 software developers and data experts.

Question on refresh

Here is a problem I have come across a few times and wonder if there is a
simple solution.

On my form I have a submit button called, say, addEntry. I do a test for it
as

if (isset($_POST[addEntry'])) { code to insert stuff into the database }

The problem is that after clicking the button, and the code returns it to
the same screen, if the user clicks the refresh button on the browser it
will add another entry. Is there a simple way to unset an html field test?
I know that unset can be unset a variable in php, but this is testing an
action on the form.

--
Shelly
Aug 21 '07 #1
4 2494
Rik
On Tue, 21 Aug 2007 16:11:35 +0200, Shelly
<sh************@asap-consult.comwrote:
Here is a problem I have come across a few times and wonder if there is a
simple solution.

On my form I have a submit button called, say, addEntry. I do a test
for it
as

if (isset($_POST[addEntry'])) { code to insert stuff into the database }

The problem is that after clicking the button, and the code returns it to
the same screen, if the user clicks the refresh button on the browser it
will add another entry. Is there a simple way to unset an html field
test?
One of the most common ways to achieve this is to do the thing on a post,
without any output (unless possibly when there are errors), and then do a
header redirect to a page (the same or another, whichever is more
appropriate). POST values will be lost on a redirect, so this snippet will
not 're-enter' the information:

<?php
if(isset($_POST['submit'])){
//do your thing here
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit;
}
//displaying of page here
?>
--
Rik Wasmus
Aug 21 '07 #2

"Rik" <lu************@hotmail.comwrote in message
news:op.txexy4dsqnv3q9@metallium...
On Tue, 21 Aug 2007 16:11:35 +0200, Shelly
<sh************@asap-consult.comwrote:
>Here is a problem I have come across a few times and wonder if there is a
simple solution.

On my form I have a submit button called, say, addEntry. I do a test
for it
as

if (isset($_POST[addEntry'])) { code to insert stuff into the database }

The problem is that after clicking the button, and the code returns it to
the same screen, if the user clicks the refresh button on the browser it
will add another entry. Is there a simple way to unset an html field
test?

One of the most common ways to achieve this is to do the thing on a post,
without any output (unless possibly when there are errors), and then do a
header redirect to a page (the same or another, whichever is more
appropriate). POST values will be lost on a redirect, so this snippet will
not 're-enter' the information:

<?php
if(isset($_POST['submit'])){
//do your thing here
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit;
}
//displaying of page here
Wow! It is as simple as that? Simply redirect the page to itself after the
insertion into the database? Thanks.

Shelly
Aug 21 '07 #3
On Aug 21, 10:17 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Tue, 21 Aug 2007 16:11:35 +0200, Shelly

<sheldonlg.n...@asap-consult.comwrote:
Here is a problem I have come across a few times and wonder if there is a
simple solution.
On my form I have a submit button called, say, addEntry. I do a test
for it
as
if (isset($_POST[addEntry'])) { code to insert stuff into the database }
The problem is that after clicking the button, and the code returns it to
the same screen, if the user clicks the refresh button on the browser it
will add another entry. Is there a simple way to unset an html field
test?

One of the most common ways to achieve this is to do the thing on a post,
without any output (unless possibly when there are errors), and then do a
header redirect to a page (the same or another, whichever is more
appropriate). POST values will be lost on a redirect, so this snippet will
not 're-enter' the information:

<?php
if(isset($_POST['submit'])){
//do your thing here
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit;}

//displaying of page here
?>
--
Rik Wasmus
It's also worth noting that this question has been asked so many times
that it shouldn't be too difficult to find some resources on it.

Aug 21 '07 #4
..oO(Shelly)
>Here is a problem I have come across a few times and wonder if there is a
simple solution.

On my form I have a submit button called, say, addEntry. I do a test for it
as

if (isset($_POST[addEntry'])) { code to insert stuff into the database }

The problem is that after clicking the button, and the code returns it to
the same screen, if the user clicks the refresh button on the browser it
will add another entry. Is there a simple way to unset an html field test?
After processing the form, send a Location header (with absolute URL)
back to the browser to redirect him to the same page. Now when a user
hits refresh, the browser will just send a normal GET request, not a
POST again.

http://www.php.net/header

Micha
Aug 21 '07 #5

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

Similar topics

1
by: SPQR | last post by:
Some time ago I set up a webcam at home and a page on my site. Every three minutes the webcam would take a picture of my backyard and ftp it to my site where it was displayed on my webcam page. ...
0
by: Roger Leigh | last post by:
I'm developing a library to allow interaction with an SQL database. Rows in the database are represented with by a user-defined row class with the following inheritance hierarchy: SigC::Object ...
7
by: Tom B | last post by:
I've written the code below to try and figure out how threading works. My assumption is that when starting a new thread it would run at the same time as the original thread. Am I wrong? I've...
6
by: David | last post by:
A user logs into a web site. He is then redirected to a web page of his choosing - based on menu options - for example: "WeeklyReport.aspx" is a page the user is currently viewing If the user...
6
by: msnews.microsoft.com | last post by:
Hello All, I am very new to ASP.NET and I have a basic question. Can somebody please explain? I have an .aspx Web Page with a textbox control. When the Page initially loads I am calling a...
5
by: Kevin | last post by:
Hi guys, I am entering some texts on textarea(HTML control) on codebehind, I have IsPostBack on page_load function. So first time IsPostBack is equal to TRUE when I submit the form, that's...
2
by: Marten Van Keer | last post by:
Hi; I have two applications A and B *** Application B listens on a network stream with a callback function:
3
by: Antoine | last post by:
What is considered best when doing an application that allows you to browse data eg by month? I've currently got an app working so it does a complete refresh when you change the month you are...
0
by: Dave Coate | last post by:
I am working on a generic way to launch multiple similar processes (threads) at once, but limit the number of threads running at any one time to a number I set. As I understand it the following...
1
by: luigi.corrias | last post by:
Hello everybody, this is a very difficult question… imagine 2 webform asp.net A and B B is an iframe inside A..
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.