I apologize if this is somehow a duplicate question. I've read a hundred posts and tried to implement every fix I uncovered to no avail.
I'm passing a variable called email_tocheck. I simply want to ensure that the email is not already in the database && that it is a "valid" email.
No matter what I do, I cannot meet the requirements of a valid email. If I simply type 'myemail@mydomain.com' in single quotes instead of $email
in the first IF statement
, the email comes back as Undefined. I'm stuck. Big time.
Am I making a stupid syntax error? I like so many am new to this. Any thoughts would be most appreciated.
$url=$_SERVER['QUERY_STRING'];
parse_str($url);
$email = "'$email_tocheck'";
$sql = "SELECT * from EmailList where Email=$email";
$conn->query($sql);
$result = $conn->query($sql);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if((mysqli_num_rows($result)>0)){
$num1 = 'Not Valid';
$num2 = 'This email has been unsubscribed.';
echo json_encode(array($num1, $num2));
} else {
$num1 = 'Valid';
$num2 = 'Send away';
echo json_encode(array($num1, $num2));
}
} else {
$num1 = 'Not Valid';
$num2 = 'A valid email is required.';
echo json_encode(array($num1, $num2,$email));
}