[eluser]babazumbula[/eluser]
Hello there,
I'm doing simple checking if username already exists in database. To achieve this in model function I've got
Code:
function existing_user(){
$this->db->where('username',$this->input->post('username'));
$query = $this->db->get('membership');
if($query->num_rows() == 1){ $this->form_validation->set_message('existing_user', 'This %s is taken') ;
return false;}
else{return true;}
}
In the controller function I've got
Code:
function create_member(){
$this->load->library('form_validation');
$this->load->model('membership_model');
$this->form_validation->set_rules('first_name','Ime','trim|required');
$this->form_validation->set_rules('last_name','Prezime','trim|required');
$this->form_validation->set_rules('email_address','E-mail','trim|required|valid_email');
$this->form_validation->set_rules('username','Korisničko ime','trim|required|callback_existing_user');
$this->form_validation->set_rules('password','Lozinka','trim|required|max_lenght[32]');
$this->form_validation->set_rules('password2','Ne poklapa se','trim|required|matches[password]');
if($this->form_validation->run() == FALSE){
$this->signup();
}
else{
$this->load->model('membership_model');
if($this->membership_model->create_member()){
$data['main_content'] = 'signup_successful';
$this->load->view('includes/template',$data);
}
else{
$this->signup();
}
}
}
But every time I try to create account with existing username in database I don't get an error.Every time the duplicate username is inserted into database. I tried even to simplify the model function like
Code:
function existing_user(){
return false;
}
which should never insert any data into database, but no use. I'm still getting inserts into database.
Where I went wrong?
Thnx in advance!