我有我试图创建一个登录脚本PHP应用程序。 当我尝试登录我收到以下错误信息:
Warning: sqlsrv_num_rows() expects parameter 1 to be resource, boolean given
它还显示“凭据无效”,即使用户名和密码是否正确。 我的代码如下:
if(isset($_POST['submit'])){
$user = $_POST['u'];
$pass = $_POST['p'];
//database connection
$serverName = "localhost\SQLEXPRESS";
$connectionInfo = array( "Database"=>"AuServer", "ReturnDatesAsStrings"=>"true");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
//query
$sql = "SELECT * FROM `users` WHERE `username` = '$user' AND `password` = '$pass'";
$params = array();
$options = array("scrollable" => SQLSRV_CURSOR_KEYSET);
$stmt = sqlsrv_query( $conn, $sql , $params, $options );
$row_count = sqlsrv_num_rows( $stmt );
echo $row_count;
if ($row_count > 0){
session_start();
$_SESSION['auth'] = "Yes";
header('Location: counterpage.php');
}
else
echo "Invalid Credentials";
}
任何帮助都感激不尽!