dombrorj Posted April 27, 2003 Posted April 27, 2003 Is there a way to avoid having multiple identical entries in a MySQL database. Visitors to my site have the option to opt-in to a newsletter by submitting their email and name to a form. This data is sent to my database, and I want to avoid people entering their info 2 or more times. Thanks for the help. Quote
dozure Posted April 27, 2003 Posted April 27, 2003 you could add a block of code to the submission script that constructs a query to search the database based upon the info they just submitted and if it gives you a match abort the operation and display an error. if it doesnt get a match go ahead and write the info to the database. something like: SELECT * FROM `tablename` WHERE `email` = "$email_they_just_submitted" and if it returns a result die ('Duplicate record detected') Quote
dozure Posted April 27, 2003 Posted April 27, 2003 I think this might work, but I'm new to programming with databses... (this is php, if you're using something else i cant help) ><?PHP $check_query = mysql_query("SELECT * FROM `table_name` WHERE `email_field_name` = $email_just_submitted_variable"); @$check = mysql_result($check_query,0,"email_field_name"); if $check = $email_they_just_submitted_variable { die ('Info already in database'); } else { code to insert the info into database } ?> Again, I wouldn't use this without having someone look at it, but I think it might work.... Quote
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.