title: Mysqli expects number of rows to be parameter
body: <p>I'm making a <code>PHP</code> form that retrieves information from a database based on a serial code entered. I am getting this error. I've tried moving stuff around and even calling the $result function inside the if statement instead of referencing the variable.</p>
  
  <blockquote>
    <p>Error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/98/10339998/html/scripts/stories.php on line 22</p>
  </blockquote>
  
  <p>Line 20-22:</p>
  
  <pre><code>$result = mysqli_query($con, $query);
  
  if (mysqli_num_rows($result)) 
  </code></pre>
  
  <p>Full Code:</p>
  
  <pre><code>&lt;?php
  if ( $_POST ) {
      $username="*******";
      $password="*******";
      $con = mysqli_connect("storycodes.db.10339998.hostedresource.com",$username,$password);
  
      if (!$con) {
          die('Could not connect: ' . mysqli_error());
      }
  
      mysqli_select_db($con, "storycodes");
  
      $code = $_POST['codeInput'];
      $code = mysqli_escape_string($con, htmlspecialchars($code)); //May not acually need htmlspecialchars
      $query = "SELECT story,video FROM `storycodes` WHERE `code` = $code";
      $result = mysqli_query($con, $query);
  
      if (mysqli_num_rows($result)) {
          $row = mysqli_fetch_assoc($result);
          mysqli_free_result($result); 
          extract($row);
          echo $story . $video;
     } else {
         echo "No Data Found. Please check your serial code to ensure that you have not incorrectly entered it. If the code is correct please email the website administrator for further assistance";
     }        
  
      mysqli_close($con);
  }
  ?&gt;
  </code></pre>