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.
Submitting form more than once!
Moderator: General Moderators
Submitting form more than once!
Last edited by dbazoo on Thu Sep 13, 2007 1:59 am, edited 1 time in total.
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?[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.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Check for the data, add a unique id into the POST data, or do a "page replace" with the 'Location' header.
You may prefer to create a "success" or "thank you" page.
Code: Select all
header('Location: http://domain.tld/path/to/form.php');Submitting form more than once
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
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
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
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
unset $_POST or $_GET, or set it to null after insert into the db, if have check the invalidate submit