2017-05-14 104 views
-1

我正在做代碼點火器中的密碼重置功能。我是新的框架。如何解決截斷不正確的DOUBLE值?

我控制器調用user_forgot_password_con 和模式是在控制器user_forgot_password_model

我有兩個功能 一個是user_forgot_password_process() 該功能拍攝的電子郵件用戶檢查數據庫,並把郵件發送到電子郵件鏈接http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email「 。$ to_email。 ''

另一個功能是user_new_password_process() 此功能允許用戶輸入新密碼

型號是user_forgot_password_model

已經3個功能之一是獲取用戶的電子郵件,檢查電子郵件 二是sendmail發送電子郵件

第三是更新用戶的密碼更新密碼..

發送電子郵件等事情是工作後

當鏈路咯咯叫着我得到在同一控制器超視距雷達的功能是電子郵件,通過$email= $this->input->get("email");

輸入新的密碼,並更新表,我得到這個錯誤

數據庫出錯 錯誤號碼:1292 截斷不正確DOUBLE值: '[email protected]' UPDATE register SET password = 0 WHERE email = 0 文件名:C:\ wamp64 \ WWW \笨\ SYSTEM \數據庫\ DB_driver.php 行號:331

如何解決呢..

我的控制器代碼

<?php 
 

 
through CI 
 

 
Class User_forgot_password_con extends CI_Controller { 
 

 
public function __construct() 
 
\t { 
 
\t \t parent::__construct(); 
 
\t \t 
 
\t \t $this->load->model('user_forgot_password_model'); 
 
\t } 
 

 
// Show login page 
 
public function index() 
 
    { 
 
\t 
 
     $this->user_forgot_password_process(); 
 
\t 
 
    } 
 
\t 
 
\t //Forgot Password Link Sending.... 
 
\t public function user_forgot_password_process() 
 
\t { 
 
\t \t // get form input 
 
\t \t $email = $this->input->post("email"); 
 
     
 
\t \t // form validation 
 
\t \t $this->form_validation->set_rules("email", "Email-ID", "trim|required|xss_clean"); 
 
\t \t 
 
\t \t 
 
\t \t if ($this->form_validation->run() == FALSE) 
 
     { 
 
\t \t \t // validation fail 
 
\t \t \t $this->load->view('header'); 
 
\t \t \t $this->load->view('user_forgot_password_view'); 
 
\t \t \t $this->load->view('footer'); 
 
\t \t } 
 
\t \t 
 
\t \t else 
 
\t \t { 
 
\t \t \t $uresult = $this->user_forgot_password_model->get_user_email($email); 
 
\t \t \t if (count($uresult) > 0) 
 
\t \t \t { 
 
\t \t \t \t //send mail 
 
\t \t \t \t if ($this->user_forgot_password_model->sendEmail($this->input->post('email'))) 
 
\t \t \t \t { 
 
\t \t \t \t \t // successfully sent mail 
 
\t \t \t \t \t $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Password Reset Link Is Sent To Your Email Reset Your Password..!!!</div>'); 
 
\t \t \t \t \t $this->load->view('header'); 
 
\t \t \t \t \t redirect('user_forgot_password_con/user_forgot_password_process'); 
 
\t \t \t \t \t $this->load->view('footer'); 
 
\t \t \t \t } 
 
\t \t \t \t else 
 
\t \t \t \t { 
 
\t \t \t \t \t // error 
 
\t \t \t \t \t $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Email Not Registered...</div>'); 
 
\t \t \t \t \t $this->load->view('header'); 
 
\t \t \t \t \t redirect('user_forgot_password_con/user_forgot_password_process'); 
 
\t \t \t \t \t $this->load->view('footer'); 
 
\t \t \t \t } \t 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t else 
 
\t \t \t { 
 
\t \t \t \t // error 
 
\t \t \t \t $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Email Not Registered..</div>'); 
 
\t \t \t \t $this->load->view('header'); 
 
\t \t \t \t redirect('user_forgot_password_con/user_forgot_password_process'); 
 
\t \t \t \t $this->load->view('footer'); 
 
\t \t \t } 
 
\t \t \t \t 
 
\t \t } \t \t 
 
\t } 
 
\t 
 
\t 
 
\t public function user_new_password_process() 
 
\t { 
 
\t \t $password = $this->input->post("passwword"); 
 
\t \t 
 
\t \t $cpassword= $this->input->post("cpasswword"); 
 
\t \t 
 
\t \t $this->form_validation->set_rules('password', 'Password', 'trim|required|md5'); 
 
\t \t $this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required|matches[password]|md5'); 
 
\t \t 
 
\t \t if ($this->form_validation->run() == FALSE) 
 
     { 
 
\t \t \t // validation fail 
 
\t \t \t $this->load->view('header'); 
 
\t \t \t $this->load->view('user_new_password_view'); 
 
\t \t \t $this->load->view('footer'); 
 
\t \t } 
 
\t \t 
 
\t \t else 
 
\t \t { 
 
\t \t  $email= $this->input->get("email"); 
 
\t \t \t 
 
      \t $this->user_forgot_password_model->update_user_password($email,$password); 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t 
 
\t \t } 
 
\t \t 
 
\t \t 
 
\t \t 
 
\t \t 
 
\t \t 
 
\t \t 
 
\t } 
 
\t 
 
\t 
 
} 
 

 
?>

我的模型是

<?php 
 
class user_forgot_password_model extends CI_Model 
 
{ 
 
\t function __construct() 
 
    { 
 
     // Call the Model constructor 
 
     parent::__construct(); 
 
    } 
 
\t 
 
\t function get_user_email($email) 
 
\t { 
 
\t \t 
 
\t \t $this->db->where('email', $email); 
 
     $query = $this->db->get('register'); 
 
\t \t return $query->result(); 
 
\t \t 
 
\t \t 
 
\t } 
 
\t 
 
\t //send verification email to user's email id 
 
\t function sendEmail($to_email) 
 
\t { 
 
\t \t $from_email = '[email protected]'; 
 
\t \t $subject = 'Reset Password Link...'; 
 
\t \t $message = 'Dear User, Please click on the below link to Reset your password. 
 
\t \t     http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email'.$to_email.''; 
 
\t \t 
 
\t \t //configure email settings 
 
\t \t 
 
\t \t $this->email->initialize(); \t 
 
\t \t //send mail 
 
\t \t $this->email->from($from_email, 'Mydomain'); 
 
\t \t $this->email->to($to_email); 
 
\t \t $this->email->subject($subject); 
 
\t \t $this->email->message($message); 
 
\t \t return $this->email->send(); 
 
\t } 
 
\t 
 
\t // Update Table 
 
\t 
 
\t function update_user_password($email,$password) 
 
\t { 
 
\t \t $data = array('password' => $password); 
 
\t \t $this->db->where('email', $email); 
 
\t \t return $this->db->update('register', $data); 
 
\t } 
 
\t 
 
\t 
 
}

+1

@tereško - 沒有人應該用php開始新項目。而這些基於意見的答案對任何人都沒有幫助。 – shaggy

+0

你爲什麼使用DOUBLE作爲電子郵件地址?電子郵件是字符串。 –

+0

我沒有在數據庫中使用Double。它還在... –

回答

0

那麼我可以告訴你一些事情。首先,錯誤信息表示您正在比較String(電子郵件)和Double(0),因此您提取的電子郵件不起作用。

http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email'.$to_email. 

我認爲你缺少一個=靠近你的鏈接結束 - >?email='.$to_email.',它是一個變量,從而通過GET可提取,沒有它,它將是鏈接的一部分,所以你需要獲取它通過$this->uri()->segment(3),它會導致像這樣的字符串[email protected]。你不想那樣。在鏈接中傳遞私密數據是一種不好的做法,因爲任何人都可以直接爲該電子郵件調用重置功能。我只是輸入http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/[email protected]我只是希望這是一個學校項目,如果不是你需要做很多關於如何安全地重置用戶密碼的研究。

user_new_password_process功能我認爲沒有什麼工作,因爲直接從郵件中的鏈接它需要你正試圖從POST讀取一些數據的方法:

$password = $this->input->post("passwword"); 

$cpassword= $this->input->post("cpasswword"); 

但有沒有在那裏。你需要這封電子郵件,帶你到一個user_new_password_show(),在那裏它加載一個包含這兩個字段的表單的視圖,再加上你需要通過電子郵件,而不是當他提交到

相關問題