SQLSRV_NUM_ROWS错误(SQLSRV_NUM_ROWS error)

2019-10-19 18:09发布

我有我试图创建一个登录脚本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";

}

任何帮助都感激不尽!

Answer 1:

不使用'username' = '$user'

写这样的: username='$user'

''username



文章来源: SQLSRV_NUM_ROWS error
标签: php sqlsrv