0

新手来了 我在使用 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);
  }

?>
4

1 回答 1

0
<?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';
    }
}
于 2013-09-27T19:12:55.783 回答