Hey :) So I'm trying to check if an user has already registered or not with their email address. The email is a unique field in the database. The problem I am having is when I am checking it, (if the email exists in the table it will return false and a message will be send to the user), num_rows() always returns false even if the email entered does not exist in the table;
I don't know if there is a problem with the post, but if I comment out the email part and register, it will work and if the email is a duplicate, the 1062 error will show.
the model funtion checkEmail()
$email_address = $this->input->post('email');
$this->db->where('email', $email_address);
$result = $this->db->get('user');
if($result->num_rows() > 0){
/*
* the email already exists
* */
return false;
}
and the controller:
$checkEmail = $this->f_model->checkEmail();
if(!$checkEmail){
/*
* if email exists
* */
$msg = '<font color=red>Email already registered.</font><br />';
$this->register($msg);
}
else {
$interest = $this->f_model->enter_register_details_01();
if(!$interest) {
$msg = '<font color=red>Password and Confirm Password do not match.</font><br />';
$this->register($msg);
}
else {
$data['msg'] = $msg;
$this->load->view("registration_view_02", array('interest' => $interest,
'message' => $data));
}
}
even if the table is empty, the message with "Email already registered" appears
Thank for your help.
in checkEmail()
function add an else statement
$email_address = $this->input->post('email');
$this->db->where('email', $email_address);
$result = $this->db->get('user');
if($result->num_rows() > 0){
/*
* the email already exists
*
*/
return false;
}else{
return true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.