title: Notice: Trying to get property of non-object at if ( $result->num_rows >0) {
body: <pre><code>&lt;?php
  
  include "conn.php";
  include "session.php";
  // Define $username and $password
  $n1 = $_POST['Name'];
  $sql = "SELECT *FROM myDB.Mynew WHERE Fname like '%".$n1."%' ";
  $result = $conn-&gt;query($sql);
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      echo '&lt;table&gt;';
      echo '&lt;tr&gt;';
      echo'&lt;th&gt;First Name&lt;/th&gt;
          &lt;th&gt;Last Name&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Password&lt;/th&gt;';
      echo'&lt;tr&gt;';
      while ($row = $result-&gt;fetch_assoc()) {
          echo '&lt;tr&gt;';
          echo '  &lt;td&gt;' . $row["firstname"] . '&lt;/td&gt;';
          echo '  &lt;td&gt;' . $row["lastname"] . '&lt;/td&gt;';
          echo '  &lt;td&gt;' . $row["email"] . '&lt;/td&gt;';
          echo '  &lt;td&gt;' . $row["password"] . '&lt;/td&gt;';
          echo '  &lt;/tr&gt; ';
      }
      echo'&lt;/table&gt;';
  } else {
      echo "&lt;br&gt; No Record Found to display";
  }
  </code></pre>
  
  <p>When I run this code I get the following notice:</p>
  
  <blockquote>
    <p>Notice: Trying to get property of non-object at line 14 which is 
    "if ( $result->num_rows >0) {"</p>
  </blockquote>