I have this sign-up form with a simple check an the e-mail already exists in database: jquery
$(document).ready(function () {
$("#btnregister").click(function () {
$.ajax({
type: 'POST',
dataType:'json',
url: '<?php echo base_url().'home/register';?>',
cache : false,
data: {
first_name: $('input[name="first-name"]').val(),
last_name: $('input[name="last-name"]').val(),
email: $('input[name="email"]').val(),
password: $('input[name="password"]').val()
},
success: function(data) {
console.log(data);
if(data.result !== 1){
ohSnap('E-mail déja utilisé.', 'red');
}
else {
ohSnap('Votre compte a été crée avec success.', 'green');
}
}
});
});
});
Controller
public function register(){
$email = $this->input->post('email') ;
$check_email = $this->users_model->user_exist($email) ;
$this->output->set_content_type('application/json') ;
if(!$check_email){
$data = array(
'first_name' => $this->input->post('first_name') ,
'last_name' => $this->input->post('last_name') ,
'email' => $this->input->post('email') ,
'password' => $this->input->post('password')
) ;
$this->users_model->create_user($data);
$this->output->set_output(json_encode(['result' => 1 ])) ;
return false;
}else{
$this->output->set_output(json_encode(['result' => 0 ])) ;
return false;
}
}
Model
public function user_exist($email){
$this->db->select('email,id ') ;
$this->db->where('email', $email);
$query = $this->db->get('users');
if($query->num_rows >= 1)
{
return $query->result();
}else{return false;}
}
The problem is that the controller always responds with the result "1", even if I register with an email that exists in the database. Is there an issue with the model function or what? Please help. Thank you!