how to check if username already exists in codeigniter

后端 未结 8 1328
无人共我
无人共我 2020-12-20 00:33

I am working on a site in codeigniter.I am not so expert using framework.Here I have to check if email already exists in database.I have coded the required functionality but

8条回答
  •  天涯浪人
    2020-12-20 00:56

    $this->form_validation->set_rules('username', 'userName', 'required|callback_exists_username');
    
    
    #uniqueness of username
        function exists_username($str)
        {
            $record_id = $this->input->post('record_id');
            $condition = array('user_id !='=>$record_id,'username'=>$str);
            $value =GetAllRecord('user_master',$condition,$is_single=true);
            if (count($value) == 0)
            {
                return TRUE;
            }
            else
            {
                $this->form_validation->set_message('exists_username', 'username already exists!');
                return FALSE;
            }
        }
    

提交回复
热议问题