php - Checking validity of userid -
how display user exist when registering new user prevent same name registered many times.this 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 exist' }else { $this->db->query("insert account(user_id,password) values ('$userid','$password'')"); }
first have 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 account(user_id,password) values ('$userid','$password')"); }else{ return false; } }
Comments
Post a Comment