Hi, i am a newbie 
ive set up a form so people can subscribe to a newsletter, their name and email is logged into a mysql database.
How do i prevent an email address being logged more than once. eg the same user subscribing multiple times
This is my code im using
<?php
include("connect.inc");
/* grabs the POST variables and puts them into variables that we can use */
$fullName=$_POST['fullName'];
$email=$_POST['email'];
//---------VALIDATION-------->
if($fullName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your full name\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for subscribing to my FREE Newsletter A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------".$fullName." has subscribed to Paso Finos Newsletter. The information given has been logged in the database--------\n"
."Full Name: ".$fullName."\n"
."E-mail: ".$email."\n";
//----------------------------------
$toAddress="#@mysite.co.uk";
$subject="newsletter";
$recipientSubject="Confirming Newsletter subscription";
$receiptMessage = "Thank you ".$fullName." for subscribing to my FREE Newsletter\n\n\nHere is what you submitted to us:\n\n"
."--------CONTACT--------\n"
."First Name: ".$fullName."\n"
."E-mail: ".$email."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("$host","$user", "$password") or die("Unable to connect!");
mysql_select_db("$database") or die("Unable to select database!");
// EXECUTE QUERY --->
$query="INSERT INTO mytable (
fullName,
email)
VALUES(
'".$fullName."',
'".$email."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
//echo mysql_affected_rows()." row inserted into the database effectively.";
// CLOSE CONNECTION --->
mysql_close($connection);
///////////////////////////////////////////////////////////////////////////////////
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - \n";
print "$error\n";
print "\n";
print "\n";
print "Please use your \"Back\" button to return to the form to correct the omissions. Thank you.\n";
}
?>
ive set up a form so people can subscribe to a newsletter, their name and email is logged into a mysql database.
How do i prevent an email address being logged more than once. eg the same user subscribing multiple times
This is my code im using
<?php
include("connect.inc");
/* grabs the POST variables and puts them into variables that we can use */
$fullName=$_POST['fullName'];
$email=$_POST['email'];
//---------VALIDATION-------->
if($fullName){//----> CHECK input
}
else{
$error.="Please, go back and fill out your full name\n";//----> ERROR if no input
}
if($email){//----> CHECK input
}
else{
$error.="Please, go back and fill out your e-mail address\n";//----> ERROR if no input
}
//-------->ERROR FREE??
if($error==""){
echo "Thank you for subscribing to my FREE Newsletter A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------".$fullName." has subscribed to Paso Finos Newsletter. The information given has been logged in the database--------\n"
."Full Name: ".$fullName."\n"
."E-mail: ".$email."\n";
//----------------------------------
$toAddress="#@mysite.co.uk";
$subject="newsletter";
$recipientSubject="Confirming Newsletter subscription";
$receiptMessage = "Thank you ".$fullName." for subscribing to my FREE Newsletter\n\n\nHere is what you submitted to us:\n\n"
."--------CONTACT--------\n"
."First Name: ".$fullName."\n"
."E-mail: ".$email."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;
//////////////////////////////////////// CONNECT TO MYSQL DB ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("$host","$user", "$password") or die("Unable to connect!");
mysql_select_db("$database") or die("Unable to select database!");
// EXECUTE QUERY --->
$query="INSERT INTO mytable (
fullName,
email)
VALUES(
'".$fullName."',
'".$email."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
//echo mysql_affected_rows()." row inserted into the database effectively.";
// CLOSE CONNECTION --->
mysql_close($connection);
///////////////////////////////////////////////////////////////////////////////////
}
else{
print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - \n";
print "$error\n";
print "\n";
print "\n";
print "Please use your \"Back\" button to return to the form to correct the omissions. Thank you.\n";
}
?>