如何使用CodeIgniter检查数据库中是否已存在电子邮件 [英] How to check if email already exists in db with CodeIgniter
本文介绍了如何使用CodeIgniter检查数据库中是否已存在电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在CodeIgniter中进行应用程序。我不知道如何在CodeIgniter中将电子邮件与db进行比较,请任何人帮助我。
I am doing application in CodeIgniter. I don't know how to compare email against db in CodeIgniter, please any one, help me.
Controller
Controller
public function signup()
{
$this->load->view('signup');
}
public function savedata(){
$this->load->library('form_validation');
$this->form_validation->set_rules('firstname', 'firstname', 'required');
$this->form_validation->set_rules('lastname', 'lastname', 'required');
if ($this->form_validation->run() == TRUE) // Only add new option if it is unique
{
$result = $this->account_model->insert();
if($result > 0)
{
$data['message'] = "Added successfully";
$this->load->view('signup',$data);
}
else
{
$this->index();
}
}
else
{
$this->load->view('signup');
}
}
如何检查电子邮件是否已经存在? / p>
How to check whether email already exists or not?
推荐答案
添加规则:
$this->form_validation->set_rules('email', 'Email', 'callback_rolekey_exists');
在同一控制器中:
function rolekey_exists($key) {
$this->roles_model->mail_exists($key);
}
在模型中,
function mail_exists($key)
{
$this->db->where('email',$key);
$query = $this->db->get('users');
if ($query->num_rows() > 0){
return true;
}
else{
return false;
}
}
这篇关于如何使用CodeIgniter检查数据库中是否已存在电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文