Okay, heres an update. $userexists stays at 0. Even though the user DOES exist in the database. It should tick to 1 because the user exists.
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
if ($email === ''){
unset($email);
}
$nemail = test_input($email);
$userexists=0;
$test = <<<SQL
SELECT email FROM `Members` WHERE email='$nemail'
SQL;
if(!$result = $mysqli->query($test)){
die('There was an error running the query');
}
while($row = $result->fetch_assoc()){
$nemail = $row['email'];
$userexists==1;
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}