检查用户标识的有效性

How to display user exist when registering new user to prevent same name registered many times.this is my model code.

class ModelUser extends CI_Model {

public function creatAccount()
{
    $userId =   $_POST['user_id'];
    $password   =   sha1($_POST['password']);

    $this->form_validation->set_rules('user_id', 'Userid',     

    trim|required|valid_userid|is_unique[account.user_id]|xss_clean');
    if ($this->form_valudation == false)
        return 'User already exist'
        }else
   {
     $this->db->query("INSERT INTO account(user_id,password)
    VALUES ('$userId','$password'')");
    }

First You have to load form validation in constructor,

$this->load->library('form_validation');

Now In creatAccount function

public function creatAccount()
{
    $userId =   $this->input->post('user_id');
    $password   =   sha1( $this->input->post('password'));
    $this->form_validation->set_rules('user_id','Userid', 'trim|required|is_unique[tablename.coloumnname]|xss_clean');
     if($this->form_validation->run() == TRUE)
        {
    $this->db->query("INSERT INTO account(user_id,password)
    VALUES ('$userId','$password')");

            }else{
         return false;
}


    }