|
Posted by Shelly on 08/21/07 14:29
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.txexy4dsqnv3q9@metallium...
> On Tue, 21 Aug 2007 16:11:35 +0200, Shelly
> <sheldonlg.news@asap-consult.com> wrote:
>
>> 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
Navigation:
[Reply to this message]
|