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? 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. 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. 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???? Link to comment https://forums.phpfreaks.com/topic/227326-simple-duplicate-protection/#findComment-1172666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.