title: An invalid parameter was passed to sqlsrv_fetch_array
body: <p>I'm using PHP web service for my android development back end. The connection with php and MSSQL Server are successful but unfortunately I stuck at this part:</p>
  
  <pre><code>&lt;?php
  session_start();
  include "connect.php";
  $user_name = $_POST["username"];
  $user_pass = strval($_POST["password"]);
  //echo $user_name;
  //echo $user_pass;
  
  //$user_name = "admin";
  //$user_pass = "admin";
  $mysql_qry="SELECT ID, Password FROM user WHERE (ID = '" . $_POST["username"] . "'  AND Password = '" . $_POST["password"] . "')";
  $result= sqlsrv_query($conn ,$mysql_qry);
  $row  = sqlsrv_fetch_array($result);
  if($row) {
  $_SESSION["ID"] = $row['ID'];
  header ('location:../createUser.php');
  }else{
       die( print_r( sqlsrv_errors(), true));
  }
  
  ?&gt;
  </code></pre>
  
  <p>It shows error:  An invalid parameter was passed to sqlsrv_fetch_array.</p>
  
  <p>This is my login form:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
      &lt;meta
        name="viewport"
        content="width=device-width, initial-scale=1, shrink-to-fit=no"
      /&gt;
      &lt;meta name="description" content="" /&gt;
      &lt;meta name="author" content="" /&gt;
  
      &lt;title&gt;Login&lt;/title&gt;
  
      &lt;!-- Custom fonts for this template--&gt;
      &lt;link
        href="vendor/fontawesome-free/css/all.min.css"
        rel="stylesheet"
        type="text/css"
      /&gt;
      &lt;link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet"
      /&gt;
  
      &lt;!-- Custom styles for this template--&gt;
      &lt;link href="css/sb-admin-2.min.css" rel="stylesheet" /&gt;
    &lt;/head&gt;
  
    &lt;body class="bg-gradient-primary"&gt;
      &lt;div class="container"&gt;
        &lt;!-- Outer Row --&gt;
        &lt;div class="row justify-content-center"&gt;
          &lt;div class="col-xl-10 col-lg-12 col-md-9"&gt;
            &lt;div class="card o-hidden border-0 shadow-lg my-5"&gt;
              &lt;div class="card-body p-0"&gt;
                &lt;!-- Nested Row within Card Body --&gt;
                &lt;div class="row"&gt;
                  &lt;img class="col-lg-6 d-none d-lg-block " src="img/Login.png"&gt;
  
                  &lt;div class="col-lg-6"&gt;
                    &lt;div class="p-5"&gt;
                      &lt;div class="text-center"&gt;
                        &lt;h1 class="h4 text-gray-900 mb-4"&gt;
                          Welcome To DEMO 1
                        &lt;/h1&gt;
                      &lt;/div&gt;
                      &lt;form class="user" method="POST" action="php/login.php"&gt;
                        &lt;div class="form-group"&gt;
                          &lt;input
                            type="text"
                            name="username"
                            class="form-control form-control-user"
                            id="exampleInputEmail"
                            aria-describedby="emailHelp"
                            placeholder="Enter Username..."
                          /&gt;
                        &lt;/div&gt;
                        &lt;div class="form-group"&gt;
                          &lt;input
                            type="password"
                            name="password"
                            class="form-control form-control-user"
                            id="exampleInputPassword"
                            placeholder="Password"
                          /&gt;
                        &lt;/div&gt;
  
                        &lt;button
                          class="btn btn-primary btn-user btn-block"
                          type="submit"
                        &gt;
                          Login
                        &lt;/button&gt;
                      &lt;/form&gt;
                      &lt;hr /&gt;
  
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;!-- Bootstrap core JavaScript--&gt;
      &lt;script src="vendor/jquery/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="vendor/bootstrap/js/bootstrap.bundle.min.js"&gt;&lt;/script&gt;
  
      &lt;!-- Core plugin JavaScript--&gt;
      &lt;script src="vendor/jquery-easing/jquery.easing.min.js"&gt;&lt;/script&gt;
  
      &lt;!-- Custom scripts for all pages--&gt;
      &lt;script src="js/sb-admin-2.min.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I already check on the parameter and everything looks just fine. Why is the error keep occur?</p>