sqlsrv_has_rows()错误PHP与MSSQL

时间:2016-04-21 11:04:12

标签: php html sql-server-2012-express

我的php页面有点问题,我只是不明白。我是新手,我真的不明白我的疑问。当我尝试执行我的程序时,错误就像这样

  

警告:sqlsrv_has_rows()要求参数1为resource,boolean   给定

这是我的代码:

<?php
    session_start();

    try{
    include 'connection.php';

    $username = $_POST['user'];
    $password = $_POST['pass'];

    //check if login form is filled
    if(empty($_POST['user']) || empty($_POST['pass'])){
    echo '<script type="text/javascript">alert("Connection established.");   </script>';
     }
    //search for user and password in the database
    $query = "SELECT * FROM [Emkaandb].[dbo].[tbl_clientslogin] WHERE email='{$username}' AND .password='{$password}' AND active='1'";
    $result = sqlsrv_query($conn, $query);
    if($result == true){
    die(print_r(sqlsrv_errors(),true));
     }
      if(sqlsrv_has_rows($result) !=1){
    echo '<script type="text/javascript">alert("Invalid email or password.");  </script>';
    }else{
     while($row = sqlsrv_fetch_array($result)){
        $_SESSION['name'] = $row['name'];

    }
    header("location: Profile.php");
    }

     }catch  (PDOException $e)
  {
    echo "Error!: " . $e->getMessage() . "
";
    die();
  }

?>

1 个答案:

答案 0 :(得分:2)

$ result return resource set id?