php - how to check duplicate value in form before insert into database -


i check duplicate data when insert duplicate in textbox display duplicate , tried insert not duplicate display "trying property of non-object"

controller

public function gamecheck(){     $this->load->library('form_validation'); // load validation     $this->form_validation->set_rules('gamename', 'checkgamename', 'required');     if ($this->form_validation->run() == true) {     if($this->input->post()) {         $this->load->model('game_m');         $gamepost = $this->input->post('gamename');         $getgame = $this->game_m->get_game($gamepost);             if($getgame->gamename!==''){             echo "duplicate";            }else{             echo "not duplicate";            }          }       }     $this->load->view('header');     $this->load->view('menu');     $this->load->view('game/gamecheck');     $this->load->view('footer'); } 

model

class game_m extends ci_model{ public function get_game($gamepost) {      $this->db->from('game');      $this->db->where('gamename',$gamepost);      return $this->db->get()->row();     } } 

for unique value can use is_unique[] in codeigniter below

$this->form_validation->set_rules('fieldname', 'msg want show', 'required|is_unique[table.coloum]'); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -