Page 1 of 1

Submitting form more than once!

Posted: Wed Sep 12, 2007 7:34 am
by dbazoo
Good day,
I know it is very simple for you all, but i am very confused how I can prevent inserting records again and again when i refresh(F5) the "add data" page. I have a form which adds data into db. When i submit the page, it goes to processing page, i.e. processingpage.php. But everytime i refresh(F5) that page, it inserts another record into db. can anyone please advise how i can prevent that?

thanks to all
Azay.

Posted: Wed Sep 12, 2007 7:57 am
by Zoxive
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
But hard to understand how your doing that.. but why not have a simple check to see if that data is already in the database?

Posted: Wed Sep 12, 2007 8:05 am
by superdezign
Check for the data, add a unique id into the POST data, or do a "page replace" with the 'Location' header.

Code: Select all

header('Location: http://domain.tld/path/to/form.php');
You may prefer to create a "success" or "thank you" page.

Submitting form more than once

Posted: Wed Sep 12, 2007 11:54 pm
by dbazoo
Thanks to all the replies.
Actually, I want to put a check in my php itself and not in Sql side. And a correction, I am submitting the form to iteself i.e., index.php. When a user submits a form, it submits the form to itself. There are checks in the scripts that checks whether the form is submitted or not and responds accordingly. But if i refresh the page at this point, it submits the page again and thus, cause the insertion again. I want to prevent this. How can I check if it has been submitted once already?

Hope it is more clearer now. :)

dbazoo

Posted: Thu Sep 13, 2007 2:12 am
by dbazoo
I've found a solution for this (I guess) but I haven't applied it. Here is the algorithm(!).
Step1. Load index.php. It will include adddata.htm page. adddata.htm contains the form that needs to be submitted.
Step2. User fills up the form. Submits it. Scripts in index.php reads/parses it.
Step3. If everything is okay, the data is inserted into db. This time it will include adddataconfirm.htm. adddataconfirm.htm will be carbon copy of adddata.htm. Here we need to pass all variables to adddataconfirm.htm from adddata.htm and make adddataconfirm.htm submit automatically with some Javascript. So the user will never know which page is loaded or executed. All he will see is the Thank You message. Here even if he refreshes the page, it won't insert the data again, as the variables from adddata doesn't exist anymore.

Does it seem workable? Please suggest if you think it should be some other way.

cheers,
azzooo

unset $_POST or $_GET may help

Posted: Thu Sep 13, 2007 3:35 am
by youscript
unset $_POST or $_GET, or set it to null after insert into the db, if have check the invalidate submit