title: Codeigniter - Trying to get property of non-object
body: <p>Please help with the error I'm getting in Codeigniter and grocery crud. Below code is throwing the following message and I'm stuck with it for a few days, I'm a total noob : (
  Error:</p>
  
  <p>A PHP Error was encountered</p>
  
  <p>Severity: Notice</p>
  
  <p>Message: Trying to get property of non-object</p>
  
  <p>Filename: controllers/examples.php</p>
  
  <p>Line Number: 70 </p>
  
  <p>ps:</p>
  
  <p>Function does what it needs, but the above error shows up.</p>
  
  <p>I appreciate your thoughts on this!</p>
  
  <pre><code> function security() {
   $method = $this-&gt;uri-&gt;segment(3); //tell ci that we are working on url segment 3, e.g. delete,  update ....
  
  if ($method == "edit" or $method == 'update_validation' or $method == 'delete') {
         $id = $this-&gt;uri-&gt;segment(4); //work on url segment 4, now pointing at posts table       primary key
          $this-&gt;db-&gt;where('posts.user_id', $this-&gt;session-&gt;userdata('id'));
          $result = $this-&gt;db-&gt;get_where('posts', array('id' =&gt; $id), 1)-&gt;row();
  
         //this is line: 70 if ($result-&gt;id != $id)
         {
             echo "You don't have access";
             exit;
         }
       else return true;
   }
  }
  </code></pre>