简体   繁体   English

MySQL检查数据库中是否存在电子邮件,并继续返回0

[英]Mysql check if email exists in database, keeps returning 0

Okay, heres an update. 好的,这是更新。 $userexists stays at 0. Even though the user DOES exist in the database. $ userexists保持为0。即使用户确实存在于数据库中。 It should tick to 1 because the user exists. 由于用户存在,因此应打勾为1。

$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;
}

This part of your code $userexists==1; 您的代码的这一部分$userexists==1;

Remove an equal sign. 删除等号。 we're not comparing here, you need to "assign". 我们不在这里进行比较,您需要“分配”。

$userexists=1;

References: 参考文献:

Plus, the test_input() function you're using isn't the best to test against an SQL injection. 另外,您使用的test_input()函数并不是针对SQL注入进行测试的最佳方法。

Use a prepared statement, please: 使用准备好的声明,请:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM