Php mysqli_fetch_assoc()未获取任何数据/获取空数据

Php mysqli_fetch_assoc()未获取任何数据/获取空数据,php,Php,所以,我正在为我的网页制作一个管理面板,但我遇到了一个bug/错误。当我想从数据库中获取数据时,使用uid作为引用,我得不到任何数据。这是我的密码: <?php session_start(); $secretToken = "UWAL2019"; include '../inc/db.inc.php'; # Including Database Info if (!isset($_POST['submit'])) { # If access has be

所以,我正在为我的网页制作一个管理面板,但我遇到了一个bug/错误。当我想从数据库中获取数据时,使用uid作为引用,我得不到任何数据。这是我的密码:

 <?php

  session_start();

  $secretToken = "UWAL2019";

  include '../inc/db.inc.php'; # Including Database Info

  if (!isset($_POST['submit'])) {
    # If access has been sent straight trough using link, not submit button

    header("Location: index.php"); # Sending client back to Login page
    exit(); # (for security purpouses) Exiting this page
  }else {
    # If access has been sent using button

    $uid = $_POST['uid']; # Getting subbmitted Username, using POST method
    $pwd = $_POST['pwd']; # Getting subbmitted Password, using POST method

    if (empty($uid) || empty($pwd)) { # If some fields are empty

      header("Location: index.php?status=empty"); # Sending client back to Login page, with status EMPTY
      exit();

    }else { # If all fields are full
      # Login credentials checking, using Database

      $sql = "SELECT * FROM admins WHERE uid='$uid';";
      $result = mysqli_query($conn, $sql);
      $resultCheck = mysqli_num_rows($result);

      if ($resultCheck > 0) {

       header("Location: index.php?status=wrongCK");
       exit();
     }else {

       if ($data = mysqli_fetch_assoc($result)) {

         if ($data['pwd'] != $pwd) {

           header("Location: index.php?status=wrongRS");
           exit();
         }else {

           $_SESSION['secretToken'] = $data['secretToken'];

           if ($_SESSION['secretToken'] != $secretToken) {

             session_destroy();
             header("Location: index.php?status=wrong_token");
             exit();

           }else {

             $_SESSION['id'] = $data['id'];
             $_SESSION['uid'] = $data['uid'];
             $_SESSION['pwd'] = $data['pwd'];
             $_SESSION['maskName'] = $data['maskName'];
             $_SESSION['email'] = $data['email'];

             header("Location: adminPanel.php");
             exit();
           }
         }
       }else {
         header("Location: index.php?status=fetch_error");
         exit();
       }
     }
    }
  }

 ?>

仅供参考:?标题中的状态变量为错误代码。我的代码停止在?status=fetch\u错误,我无法通过它。有人能帮我吗?

我想你的问题是这一行:

if ($resultCheck > 0) {
    header("Location: index.php?status=wrongCK");
    exit();
}
您基本上是说,如果找到了用户,请重定向。我认为你应该:

if ($resultCheck < 1) {
    header("Location: index.php?status=wrongCK");
    exit();
}

当找不到用户时,它将重定向。

停止一直重定向,而是进行一些合理的调试输出-检查函数返回值,询问数据库可能发生了什么错误,等等。这段代码太乱了。。尝试使用函数,它将使您的代码更线性,更易于理解和修改。此外,您还需要避免您的输入或您的数据库可能会被删除!!!