how to check duplicate value in form before insert into database
<blockquote>
  <p>I would like to check duplicate data when i insert duplicate in textbox it will display duplicate and I tried to insert not duplicate it display "Trying to get property of non-object"</p>
  
  <p>Controller</p>
</blockquote>

<pre><code>public function gamecheck(){
    $this-&gt;load-&gt;library('form_validation'); // load from validation
    $this-&gt;form_validation-&gt;set_rules('gamename', 'Checkgamename', 'required');
    if ($this-&gt;form_validation-&gt;run() == TRUE) {
    if($this-&gt;input-&gt;post()) {
        $this-&gt;load-&gt;model('game_m');
        $gamepost = $this-&gt;input-&gt;post('gamename');
        $getgame = $this-&gt;game_m-&gt;get_game($gamepost);

           if($getgame-&gt;gamename!==''){
            echo "duplicate";
           }else{
            echo "not duplicate";
           }
         }
      }
    $this-&gt;load-&gt;view('header');
    $this-&gt;load-&gt;view('menu');
    $this-&gt;load-&gt;view('game/gamecheck');
    $this-&gt;load-&gt;view('footer');
}
</code></pre>

<blockquote>
  <p>Model</p>
</blockquote>

<pre><code>class Game_m extends CI_model{
public function get_game($gamepost) {
     $this-&gt;db-&gt;from('game');
     $this-&gt;db-&gt;where('gamename',$gamepost);
     return $this-&gt;db-&gt;get()-&gt;row();
    }
}
</code></pre>