Jump to content

Redundant Mysql Entries


Recommended Posts

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.

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...