如何在两个不同的表中使用相同的列名(电子邮件,密码)重置密码
模型代码如下所示
public function resetpassword($user) {
$data = array(
'password' => ($this->input->post('newpassword'))
);
//$where = "id=5";
$where = "id=$user";
$this->db->where($where);
$this->db->update('supplier_registration', $data);
}
控制器代码如下所示
public function ResetPassword() {
$emaill = $this->input->post('emaill');
$otp = $this->input->post('otp');
//$this->form_validation->set_rules('emaill', 'emaill', 'required|min_length[10]|max_length[30]|matches[otp]');
$this->form_validation->set_rules('otp', 'otp', 'required|min_length[6]|max_length[6]');
$this->form_validation->set_rules('newpassword', 'newpassword', 'trim|required|max_length[15]|min_length[8]|alpha_numeric|matches[confirmpassword]');
$this->form_validation->set_rules('confirmpassword', 'Confirm password', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
} else {
if($this->session->userdata('otp') == "$otp" && $this->session->userdata('findemaill') == "$emaill" ) {
$user = $this->session->userdata['idd'];
$this->load->model('Login_model');
$result['data'] = $this->Login_model->resetpassword($user,$emaill);
$this->session->set_flashdata('success_msg', 'successfull reset the password');
$this->load->view('login');
}
}
}
答案 0 :(得分:0)
首先,您需要在模型中的resetpassword($user,$email)
函数中使用两个参数。然后使用$this->db->set()
设置新密码,如下所示:
public function resetpassword($user,$email) {
$new_password = $this->input->post('newpassword');
$this->db->set('password',$new_password );
$this->db->where('id',$user);
$this->db->update('supplier_registration');
}
答案 1 :(得分:0)
public function ResetPassword()
{
$emaill = $this->input->post('emaill');
$otp = $this->input->post('otp');
//$this->form_validation->set_rules('emaill', 'emaill', 'required|min_length[10]|max_length[30]|matches[otp]');
$this->form_validation->set_rules('otp', 'otp', 'required|min_length[6]|max_length[6]');
$this->form_validation->set_rules('newpassword', 'newpassword', 'trim|required|max_length[15]|min_length[8]|alpha_numeric|matches[confirmpassword]');
$this->form_validation->set_rules('confirmpassword', 'Confirm password', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
} else {
if($this->session->userdata('otp') == "$otp" && $this->session->userdata('findemaill') == "$emaill" ) {
$user = $this->session->userdata['idd'];
$this->load->model('Login_model');
$result['data'] = $this->Login_model->resetpassword($user,$emaill);
//as now you have got $user and $email, fire same query to another model having different table name
$result['data1'] = $this->Another_table_model->resetpassword($user,$emaill);
$this->session->set_flashdata('success_msg', 'successfull reset the password');
$this->load->view('login');
}
}
}
检查此代码并告诉我们,您将在同一个函数中调用两个不同模型的方法