I'm experiencing a weird problem and wondering if someone could take a look. I wrote a very simple function to check for duplicate entries in a db.
function chkDuplicates($tblName, $rowName, $var)
{
if(@mysql_num_rows(mysql_query("SELECT * FROM $tblName WHERE $rowName = '$var'")) == 0)
{
return false;
}
return true;
}
Users use a form to enter their name and email address for a simple mailing list. I use chkDuplicates($tblName, $rowName, $var) to see if they already exist. If so they are told there email is already in the db. The problem is that once an email has existed in the db and then deleted...it acts as if it is still there and won't allow it to be entered again.
Also...I disabled the duplicate check for testing purposes and would use my own email over and over. At one time I had as many as 20 duplicate entries of my own email. I then deleted all but one, but when I send a mail (for mail list) I receive 20 copies not 1. Its like they are cached.
Here is an abbreviated version of the code.
$subject and $message are passed in...
if($_GET['mail_list'] == 'submitted')
{
$fv->isEmpty('subject', 'Please enter a subject.');
$fv->isEmpty('message', 'Please enter a message.');
if($fv->isError())
{
$errors = $fv->getErrorList();
$fv->displayErrors($errors);
}
else
{
if(chkDuplicates("mail", "email", $email))
{
$msg = 'Duplicate';
$fv->errMsg($msg);
}
else
{
$sql = "select email from mail";
$res = mysql_query($sql) or die("Couldn't send mail at this time."); // change this
while($myrow = mysql_fetch_array($res))
{
$email_addr = $myrow[0];
mail("$email_addr", "$subject", $message, $headers);
}
if(mail("$email_addr", "$subject", $message, $headers))
{
genMsg('sent', '');
}
else
{
genMsg('mail_fail', '');
}
}
}
}
Thanks 🙂