title: mysqli_num_rows() expects paramter though an earlier query on the same page works
body: <p>I am getting an error when querying a table in my MySQL database. It's the standard one with mysqli_num_rows when there is no value in the variable that's being passed:</p>
  
  <pre><code>Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in folder/file.php on line 29
  </code></pre>
  
  <p>Problem is I can't find the syntax error. I've looked at it a ton of times. Here's what my code is:</p>
  
  <pre><code>$sql_messages = "SELECT * FROM messages WHERE to='$userid'";
  $result_messages = $mysqli-&gt;query($sql_messages);
  $num_rows_messages = mysqli_num_rows($result_messages);
  </code></pre>
  
  <p>I tried a fetch array but that gave me the similar error. Nothing is getting passed into $result_messages I suppose. I echo'ed out $userid and that has a value and I've checked my database and there is a table 'messages' with a field 'to'. I'm connected to the right database because I have this code before this query:</p>
  
  <pre><code>$sql="SELECT * FROM users WHERE firstname='$firstname' &amp;&amp; lastname='$lastname'";
  $result = $mysqli-&gt;query($sql);
  $row = mysqli_fetch_array($result);
  </code></pre>
  
  <p>And that works fine. It is the third query on the page, is there some sort of limit? Does anyone see a syntax error that I'm overlooking? Thanks, sorry if it's a small little error!</p>