用戶提交郵件 id 后,otp 將被發送到該電子郵件 id,但我的代碼無法正常作業,它將電子郵件 id 發布到資料庫中,而不是 otp。請問有人可以幫忙嗎?
控制器代碼 auth.php
public function register()
{
$alphabet = '1234567890';
$otp = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i ) {
$n = rand(0, $alphaLength);
$otp[] = $alphabet[$n];
}
$newotp = implode($otp);
// $data['otp'] = $newotp;
$to = $this->input->post('email');
$subject = "OTP FOR LOGIN";
$message = '
Dear, User ,<br> <br>
Thanks You For Requesting OTP.<br><br>
Your Username is - ' . $to . ' And <br><br>
Your Password Is - <b>' . $newotp . '</b> <br><br>
Thank you!<br><br>
This is an autogenerated email. Please do not reply to this email.
<br><br>
';
$mail = $this->Others->send_email($to, $subject, $message);
$data = $this->user_model->insert('cred', ['email' => $to], ['otp' => ($newotp)]);
redirect(base_url() . 'auth/login');
}
型號代碼 user_model.php
public function insert($table, $data = array())
{
$this->db->insert('cred', $data);
$afftectedRows = $this->db->affected_rows();
if ($afftectedRows == 1) {
$id = $this->db->insert_id();
return $id;
} else {
return FALSE;
}
}
uj5u.com熱心網友回復:
在您的控制器中,您實際上將三個引數傳遞給$this->user_model->insert()而不是兩個。第二個引數需要是一個陣列。
嘗試使用此更新以下行:
$data = $this->user_model->insert('cred', ['email' => $to, 'otp' => $newotp]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/431246.html
