title: PHP Search Query Error: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean
body: <p>I'm trying to use a textbox and button to search my database then have it be displayed in a table, still starting out so I'm very shaking on this. I keep getting this error:</p>
  
  <p><strong>Warning: sqlsrv_fetch_array(): 2 is not a valid ss_sqlsrv_stmt resource in C:\RDEUsers\NET\531545\LocationPOST.php on line 55</strong></p>
  
  <p>Very confused as to what exactly is wrong.</p>
  
  <pre><code>        &lt;?php
  
  if(isset($_POST['Search']))
  {
      $SearchValue = $_POST['SearchValue'];
      // search in all table columns
      // using concat mysql function
      $LocationQuery = "SELECT * FROM Location WHERE (Username, First_Name, Surname, Current_Location) LIKE '%".$SearchValue."%'";
      $search_result = FilterTable($LocationQuery);
  
  }
   else {
      $LocationQuery = "SELECT * FROM Location";
      $search_result = FilterTable($LocationQuery);
  }
  
  // function to connect and execute the query
  function FilterTable($LocationQuery)
  {
  $server = 'SQL2008.net.dcs.hull.ac.uk';
  $connectionInfo = array("Database"=&gt;"rde_531545");
  $conn = sqlsrv_connect($server,$connectionInfo);
  
  $Filter_Result = sqlsrv_query($conn, $LocationQuery);
   return $Filter_Result;
  }
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt; Location Tracker &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;center&gt;&lt;h1&gt; ACW Location Tracker &lt;/h1&gt;&lt;/center&gt;
  
  &lt;body&gt;
  
   &lt;form action="LocationPOST.php" method="POST"&gt;
  &lt;input type="text" name="SearchValue" placeholder="Username"&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit" name="Search" value="Search"&gt;&lt;br&gt;&lt;br&gt;
  
  
  &lt;table&gt;
  &lt;tr&gt;
  &lt;th&gt; Username &lt;/th&gt;
  &lt;th&gt; First_Name &lt;/th&gt;
  &lt;th&gt; Surname &lt;/th&gt;
  &lt;th&gt; Current_Location &lt;/th&gt;
  
  &lt;/tr&gt;
  
  &lt;?php while($row = sqlsrv_fetch_array($search_result)):?&gt;
  
         &lt;tr&gt;
                      &lt;td&gt;&lt;?php echo $row['Username'];?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $row['First_Name'];?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?phpecho $row['Surname'];?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $row['Current_Location'];?&gt;&lt;/td&gt;                 
         &lt;/tr&gt;
  
  &lt;?php endwhile;?&gt;
  
  &lt;?php
  
  
  
  //set timezone to current timezone GMT
  date_default_timezone_set('Europe/London');
  
  $server = 'SQL2008.net.dcs.hull.ac.uk';
  //sets up connection to database
  $connectionInfo = array("Database"=&gt;"rde_531545");
  $conn = sqlsrv_connect($server,$connectionInfo);
  //creates a table called location in the database
  $LocationQuery='create table Location ';
  $LocationQuery .= '(Username int NOT NULL IDENTITY(500, 23), First_Name varchar(50) NOT NULL, Surname varchar(50) NOT NULL, Current_Location varchar(50) NOT NULL, Date date NOT NULL, PRIMARY KEY (Username))';
  $result = sqlsrv_query($conn, $LocationQuery);
  
  if (!$result)
  {
   if( ($errors = sqlsrv_errors() ) != null)
  {
  foreach( $errors as $error )
  {
  echo "&lt;p&gt;Error: ".$error[ 'message']."&lt;/p&gt;";
  }
  }
  }
  else
  {
  echo "&lt;p&gt;DB successfully created&lt;/p&gt;";
  }
  //close server connection
  sqlsrv_close($conn);
  
  $server = 'SQL2008.net.dcs.hull.ac.uk';
  $connectionInfo = array( "Database"=&gt;"rde_531545");
  $conn = sqlsrv_connect($server,$connectionInfo);
  date_default_timezone_set('Europe/London');
  $date =  new DateTime('');
  $dateStr = $date-&gt;format("Y-m-d H:i:s");
  $d=strtotime("");
  $insert_query = "INSERT INTO Location (First_Name, Surname, Current_Location) VALUES (?, ?, ?, ?)";
  $params = array("John","Doe","Hull" );
  $result = sqlsrv_query($conn,$insert_query,$params);
  $params = array("Jane","Doe","London");
  $result = sqlsrv_query($conn,$insert_query,$params);
  $params = array("Jon","Doe","Sheffield");
  $result = sqlsrv_query($conn,$insert_query,$params);
  
  //select all data from table Location in the database
  $LocationQuery='SELECT * FROM Location';
  $results = sqlsrv_query($conn, $LocationQuery);
  // while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC))
  // {
  // echo '&lt;p&gt;'.$row['Username'].' '.$row['First_Name'].' '.$row['Surname'].' '.$row['Current_Location']. '&lt;/p&gt;';
  // }
  // sqlsrv_close($conn);
  
  //display the associative array results in a table
  while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC))
  {
      echo "&lt;tr&gt;&lt;td&gt;".$row['Username']."&lt;/td&gt;&lt;td&gt;".$row['First_Name']."&lt;/td&gt;&lt;td&gt;".$row['Surname']."&lt;/td&gt;&lt;td&gt;".$row['Current_Location']."&lt;/td&gt;&lt;td&gt;".$dateStr = $date-&gt;format("Y-m-d H:i:s")."&lt;/td&gt;&lt;/tr&gt;";  
  }
  
  sqlsrv_close($conn);
  ?&gt;
  
  &lt;/table&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>