brianstorm Posted March 2, 2007 Share Posted March 2, 2007 Hi, I'm hoping for some guidance here as I've been messing about for too long now and as I am not entirely sure of exactly what I am trying to do I am going in circles.... I have a form on a php page which is used to insert data into a mysql db. The same page does the processing. At the moment clicking refresh on the browser enters the same data into the db giving a dupliacte entry. My question is what is the best way to avoid this? (The page has $_SESSION and $_POST variables currently in use) If anyone cares to explain I'd be most greatful.. Thanks Brian Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/ Share on other sites More sharing options...
DanDaBeginner Posted March 2, 2007 Share Posted March 2, 2007 you should use another page for inserting/deleting/updating data or else everytime the page is refresh it will do the same thing.. Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-197811 Share on other sites More sharing options...
DanDaBeginner Posted March 2, 2007 Share Posted March 2, 2007 the best example would be: main.php ->here is were the user can insert data, and on the form action="add.php" add.php-> this page should contain the query and it will redirect to main.php after the insert query here.... header('Location: main.php'); Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-197812 Share on other sites More sharing options...
fenway Posted March 2, 2007 Share Posted March 2, 2007 That's right... always redirect after a post. Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-198071 Share on other sites More sharing options...
brianstorm Posted March 5, 2007 Author Share Posted March 5, 2007 thanks for the advice... it would seem to make data entry a bit clunky though.... if i have to redirect to a new page, and then the user has to click again to return to the form page.... is there a solution to that? can i redirect after data entry? Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-199745 Share on other sites More sharing options...
fenway Posted March 5, 2007 Share Posted March 5, 2007 Sure, of course... after the post to your processing script, near the last line, spit out a location header. Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-199904 Share on other sites More sharing options...
brianstorm Posted March 5, 2007 Author Share Posted March 5, 2007 ok thanks, will give that a go.... one last question ->> do I explicitly need to clear /reset any $_POST variables? or $_SESSION variables? am i correct in thinking that $_POST variables will be cleared unless I pass them on, and the $_SESSION variables will continue to exist unless reset / destroyed? Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-199935 Share on other sites More sharing options...
fenway Posted March 5, 2007 Share Posted March 5, 2007 For the POST, you're definitely correct... I have no idea about PHP sessions. Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-199957 Share on other sites More sharing options...
brianstorm Posted March 5, 2007 Author Share Posted March 5, 2007 Many thanks to you both for your time & advice! Very much apprecciated! Quote Link to comment https://forums.phpfreaks.com/topic/40849-solved-best-way-to-avoid-duplicate-mysql-entries-when-user-clicks-refresh/#findComment-199963 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.