检查mysqli_query是否没有值?

时间:2013-06-08 06:09:30

标签: php mysql mysqli

我有一个注册表单的代码。我想查看电子邮件,看它是否已经登录数据库,如果是,则返回错误。

$name = $_POST['name'];
$email = $_POST['email'];

$result = mysqli_query($connection,"SELECT * FROM users WHERE email='$email'");

if($result=="")
{
echo("email was not found");
}
else
{
    echo("email was found");
}

如果结果显示为空,我遇到了麻烦。我已经尝试过使用几件事,如果找不到任何东西,就无法弄清楚如何让它正常工作。

4 个答案:

答案 0 :(得分:8)

使用mysqli_num_rows检查是否有任何行返回。

答案 1 :(得分:2)

像这样使用mysqli_num_rows

if(mysqli_num_rows($result)==0) echo("email was not found"); else echo("email was found");
希望它能帮到你..

答案 2 :(得分:0)

使用此功能。

$name = $_POST['name'];
$email = $_POST['email'];

$result = mysqli_query($connection,"SELECT * FROM users WHERE email='".$email."'");

if(!$result)
{
  echo("email was not found");
}
else
{
  echo("email was found");
}

答案 3 :(得分:-1)

if(empty($result))
{
    echo("email was not found");
}