没有查询结果。它不是真的,不是假的,是空的

时间:2016-03-07 20:59:27

标签: php mysqli

我做了一些查询来检查用户名和密码。 当我输入正确的数据时,它工作正常, 如果我把正确的电子邮件和错误的密码工作正常, 当我把一个不存在的用户名我得不到结果和白色屏幕。现在echo命令跳转。看起来它卡住了,没有错误。 任何想法?

if (isset($email) && isset($password)) {
        $query  = "SELECT * ";
                $query .= "FROM users ";
                $query .= "WHERE user_email = '{$email}' ";
                $query .= "LIMIT 1";

                $result = mysqli_query($connection, $query);


                if ($result) {

                    while ($row = mysqli_fetch_assoc($result)) {
                        if ($row["user_password"] == $password) {
                            echo json_encode($row);

                        } else {

                            echo ('{"user_id":"0","user_name":"","user_email":"","user_password":"","register_date":"2016-03-05","confirm":"0"}');
                        }

                    }


                } else {
                  echo("error");
                }
    } else {
        echo($result);
        echo("Missing Vars");
    }

1 个答案:

答案 0 :(得分:0)

我敢打赌“if($ result)”是真的,但它永远不会进入while循环,因为没有要迭代的行。这将导致空白屏幕。尝试回显从数据库返回的内容并回显每个嵌套以查看输出内容。如下所示:

if ($result) {
  echo("if $result must be true because I made it in");
  while ($row = mysqli_fetch_assoc($result)) {
    echo("I made it in the while loop if there are rows in my result");
    if {
      echo("I made it in while's if");
      ...
    } else {
      echo("I made it in while's else");
      ...
    }
  }
} else {
  echo("if $result must be false because I didn't make it in");
  echo("error");
}

我敢打赌,使用上面的例子你会看到:

if $result must be true because I made it in

这就是你所能看到的全部