2017-02-28 106 views
-1

如何使用相同的列名(電子郵件,密碼)在兩個不同的表如何使用兩個不同的表

型號代碼重置口令重置密碼如下所示

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

內不同型號的2種方法你一樣想要使用單個函數重置具有相同列名的兩個表中的密碼? –

+0

是的,我想重置密碼,使用兩個不同的表列名稱是相同的 –

+0

如果這些表是1to1相關的,就像每個行具有相同的ID值,您可以設置更新表後的觸發器。 – Tpojka

回答

0

首先你需要兩個參數resetpassword($user,$email)功能model.Then使用$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'); 
     } 
+0

但我想重置密碼使用兩個不同的表列名稱是同一個例子一個表supplier_registration另一個表customer_registration –

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'); 


     } 


    } 
} 

檢查這個代碼,讓我知道,你會調用功能相同

+0

您的代碼正在工作,但一個問題發生在兩個表相同的ID意味着它將重置在兩個表密碼 –

+0

你可以保持條件對此,或者你有任何比我可以修改它 –

+0

好吧,先生修改代碼 –

相關問題