php_guy Posted October 24, 2010 Share Posted October 24, 2010 Hello all, As the title says: For sake of example, let's say I have a form with a couple text boxes and a submit button. When you hit submit, the data from the text boxes is translated into a database record. Howver, refershing the page will this record again and again -- which I do not want. How can I prevent this? Keeping in mind the business logic of my applicatoin allows the same record to be entered twice -- however, it should only happen if the user intentionally visits the form agian, and enters the same data. It should not happen on a page refresh. I assume this is a common problem...? Any thoughts? Thanks! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 24, 2010 Share Posted October 24, 2010 You can use a header() redirect after a successful database insert. Then there will be nothing in the $_POST array if the page is inadvertently refreshed. if( mysql_affected_rows() > 0 ) { header('Location: same_page_or_success_message.php'); } Or, you can check for duplicate records first, and present the user with a confirmation dialog. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.