Reputation: 63
Here's my function:
function checkForDuplicates($items, $checkitem)
{
$rows = explode("\n", $items);
foreach($rows as $item)
{
if($item === $checkitem)
return TRUE;
}
return FALSE;
}
I've confirmed that its returns are accurate and work properly. Here's where the function gets called and I run into an issue:
$email = sanitizeInput($_POST['email']);
$email = strtolower($email);
$emails = file_get_contents('emails.txt');
if(checkForDuplicates($emails, $email) == FALSE);
{
$emailFile = fopen('emails.txt','a') or die ('Sorry. Subscriptions are disabled for the time being.');
fwrite($emailFile, $email."\n");
fclose($emailFile);
}
No matter what I input, it writes to the file either way. I can't possibly understand why such a simple comparison isn't working.
Upvotes: 0
Views: 35
Reputation: 22442
Your problem comes from the trailing ";" here
if(checkForDuplicates($emails, $email) == FALSE);
It boils down to an if with an empty statement.
The following block (file appending) is always executed because it is not part of the condition.
Upvotes: 3