vendredi 8 juillet 2016

simple comparison in PHP not working

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 and I can't possibly understand why such a simple comparison isn't working.
Any insight would be appreciated as I truly have no idea what's going on.
Thanks in advance,
Zach

Aucun commentaire:

Enregistrer un commentaire