PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey.... I am unsure exactly how to prevent resubmissions into my database when I refresh the browser. I am using a mysql insert statement. So if I enter text in the form and click submit it is added to the database; however if I refresh the browser on that page the same text is duplicated in the database?
But when I use this or some combination of this it says headers already sent out. I have made sure that there is no extra white space and all of that. How do I use this code or something else to keep the browser from resubmitting the text into the database?
You could always check to see if there's a duplicate row in the DB first, but that still doesn't address the problem of the headers already being sent. Something is being sent, somewhere.
If there any way that you could offer me an example or something on exactly how to accomplish this? I am new to PHP and this is on area that is really confusing to me. Here is the snipping of the code I am trying to keep from resubmitting:
Ok, well I got the browser to stop saying header already sent out by using the ob_start(); and ob_flush(). I placed the ob_start() at the beginning of the html and css in the page and the placed the ob_flush() after my header redirct statement. However the redirect is not preventing resubmissions, actually it is not working at all. How do I get this to work?
It seems your goal is to prevent the reposting of data by the visitor reloading the page. The common approach for dealing with this is to have the processing page (the page inserting the records) sending only a redirect header (back to the form page) rather than any html.
form page -> processing page -> form page
If the redirect is correctly being sent, then the visitor will be unable to insert additional rows by simply clicking the reload button. Check to make sure the browser is receiving the Location header.
call the function when the user click on the submit button only.
for example submit button name is txtsubmit
if(isset($_POST[txtsubmit]))
{
function add_insert()
{
insert statement
}
}