title: Trying to get property 'num_rows' of non-object
body: <p>Could someone help me to correct this code? </p>
  
  <p>I keep getting this error:- </p>
  
  <blockquote>
    <p>Notice: Trying to get property 'num_rows' of non-object  </p>
  </blockquote>
  
  <pre><code>&lt;?php
  
    $test = $_GET['param'];
    $sql =" SELECT * FROM img WHERE id = $test ";
    $result = $conn-&gt;query($sql);
  
    if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
        echo " &lt;div class='col-lg-9'&gt; ";
  
        echo " &lt;div class=card mt-4&gt; ";
        echo " &lt;img src=http://placehold.it/900x400 class=img-responsive alt=Responsive image&gt; ";
        echo " &lt;div class='card-body'&gt; ";
        echo " &lt;a class=pull-right&gt; &lt;button type=button class='btn btn-primary'&gt;Prezzo " .$row["prz"]. " €&lt;/button&gt; &lt;/a&gt; ";
  
        echo " &lt;h3 class=card-title&gt;" .$row["nome"]. "&lt;/h3&gt; "  ;
        echo "&lt;br&gt;";
        echo "&lt;br&gt;";
        echo " &lt;p class=card-text&gt;" .$row["ldscr"]. "&lt;/p&gt; ";
        echo "&lt;/div&gt;";
        echo "&lt;/div&gt;";
        echo "&lt;br&gt;";
      }
    } 
  
  ?&gt;
  </code></pre>