title: Cannot get data from MySQL table with PHP request
body: <p>I'm new to PHP and MySQL and trying to get a row returned from my table matching input from a HTML form.  Code as follows:</p>
  
  <pre><code>$connect = mysqli_connect('localhost', 'root', '', 'testdb') 
  OR die('Could not connect to the server' . mysqli_connect_error());
  
  $query = ("SELECT * FROM users WHERE username = '$username'");
  $result = mysqli_query($connect, $query);
  $hits = mysqli_affected_rows($connect);
  
  if ($hits &lt; 1) {
     echo "Incorrect password or username";   
     die("&lt;br /&gt;&lt;a href='index.php'&gt;Try Again&lt;a/&gt;");
  } else {
     // other not relevant code here
  }
  </code></pre>
  
  <p>The var <code>$hits</code> always comes back as 0, when there is data in the table matching the query.</p>
  
  <p><code>var_dump($result)</code> returns:</p>
  
  <pre><code>object(mysqli_result)#2 (5) { ["current_field"]=&gt; int(0) ["field_count"]=&gt;
  int(4) ["lengths"]=&gt; NULL ["num_rows"]=&gt; int(0) ["type"]=&gt; int(0) } 
  </code></pre>