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! Link to comment https://forums.phpfreaks.com/topic/216705-prevent-submission-of-form-when-page-refreshed/ 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. Link to comment https://forums.phpfreaks.com/topic/216705-prevent-submission-of-form-when-page-refreshed/#findComment-1125868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.