Mysqli 结果问题


Mysqli Result problems

新手在这里。我在使用 mysqli 的 php 代码时遇到问题。我已将限制设置为 1,但是当我尝试进行一些测试时,例如在 mysqli_stmt_num_rows($stmt) 处放置回声;看看它是否真的拿到了什么...但结果结果是 0。我真的不知道该怎么办了。希望有人能帮助我。

这是我的登录代码:

<?php
$con = mysqli_connect("localhost", "root", "", "pamsignup")
or die('error in connection'.mysqli_connect_error());
  if(isset($_POST['login'])){
    $stmt = mysqli_prepare($con, "SELECT username, password FROM registries               
         WHERE username=? AND  password=? LIMIT 1");
    $username= $_POST['username'];
    $password = $_POST['password'];
    mysqli_stmt_bind_param($stmt, 'ss', $username, $password);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $username, $password);
    mysqli_stmt_fetch($stmt);
    mysqli_stmt_store_result($stmt);
    echo mysqli_stmt_num_rows($stmt);
    if(mysqli_stmt_num_rows($stmt) == 1)
    { 
      header('Location: PAM-home.php');
    }
    else 
    {   
      //header('Location: PAM-login.php'); 
      echo 'Wrong Password';
    }
      mysqli_stmt_close($stmt);
  }
?>
<?php
error_reporting(E_ALL);
if(isset($_POST['username']))
{
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $con = mysqli_connect("localhost", "root", "", "pamsignup")
    $sql = "SELECT 1 FROM registries WHERE username=? AND  password=?";
    $stmt = mysqli_prepare($con, $sql);
    mysqli_stmt_bind_param($stmt, 'ss', $_POST['username'], $_POST['password']);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_store_result($stmt);
    if(mysqli_stmt_num_rows($stmt))
    { 
        header('Location: PAM-home.php');
    }
    else 
    {   
      //header('Location: PAM-login.php'); 
      echo 'Wrong Password';
    }
}