tibberous Posted February 11, 2011 Share Posted February 11, 2011 I have a contact form, and I want to make sure it doesn't send a bunch of duplicates if the page is refreshed after being submitted. Simple way is to make sure this record isn't identical to the one before it: select * from `contacts` where `Name`='$name' and `Phone`='$phone' and `Message`='$message' and `Subject`='$subject' and `Email`='$email' But, that checks against all records. While not likely, this could cause problems, if the same customer came back a month later and put in the same exact contact. Any way I can check it only against the very last record in the database? Something like: and `id`=XX , where XX is one less than the current auto inc id? Quote Link to comment https://forums.phpfreaks.com/topic/227326-simple-duplicate-protection/ Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2011 Share Posted February 11, 2011 I suppose after the INSERT, you could set a $_SESSION var to the value of mysql_insert_id(), then if isset($_SESSION['insert_id']), check to see if the proposed INSERT is a duplicate of the last one. Quote Link to comment https://forums.phpfreaks.com/topic/227326-simple-duplicate-protection/#findComment-1172568 Share on other sites More sharing options...
Jessica Posted February 11, 2011 Share Posted February 11, 2011 Does your table have an id or anything to indicate where it was sent? I'd select the most recent entry, based on the ID or timestamp, that matches your inputs. If it's within a few minutes (or seconds), you know to ignore it. If it's older than that, it's a valid new form. Quote Link to comment https://forums.phpfreaks.com/topic/227326-simple-duplicate-protection/#findComment-1172573 Share on other sites More sharing options...
litebearer Posted February 11, 2011 Share Posted February 11, 2011 order by id desc limit 1 - then grab the result and compare???? Quote Link to comment https://forums.phpfreaks.com/topic/227326-simple-duplicate-protection/#findComment-1172666 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.