我正在为我的Web应用程序创建一个登录脚本,并且我正在尝试使用它$count = mysqli_stmt_num_rows($stmt);来查找从sql select语句返回的行数,因此我可以决定是否应该启动会话.
问题是,$ count始终为0,即使我输入与我的数据库中的数据匹配的有效用户名和密码.我已经测试了select语句,它运行正常.没有给出错误,语法,SQL或其他内容,所以我对于发生什么事情感到有些困惑.
码:
<?php
$link = mysqli_connect("localhost", "****", "****", "****");
//check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// Move to MySQL(i) as MySQL is now obslete and use Prepare statment for protecting against SQL Injection in better and easier way
$stmt = mysqli_prepare($link, 'SELECT username, password FROM `users` WHERE `username` = ? AND `password` = ?');
/* bind parameters for markers …Run Code Online (Sandbox Code Playgroud)