[英]Email already exists in database Codeigniter
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;
我遇到的问题是当我检查它时(如果表中存在该电子邮件,它将返回false并将一条消息发送给用户),即使输入的电子邮件不存在于num_rows()中,它也会始终返回false桌子;
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. 我不知道帖子是否有问题,但是如果我注释掉电子邮件部分并注册,它将起作用,如果电子邮件重复,则会显示1062错误。
the model funtion checkEmail() 模型功能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 在
checkEmail()
函数中添加else语句
$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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.