更新数据时如何解决“'where子句'中的未知列'Array'”-Codeigniter

时间:2019-08-01 21:18:27

标签: php codeigniter email

我已经在代码点火器中创建了小型应用程序,目前在此应用程序中创建一个忘记密码模块。 我创建了一个函数,但是不知道为什么它不起作用;我需要随机的,自动生成的密码才能通过电子邮件发送出去,但是当我单击“提交”按钮时,它说的是“数组到字符串的转换错误”,所以给我一些建议。

这是我的观点

<?php

$attributes = array('class' => 'user', 'method' => 'post' );

echo form_open('Authentication/forget_password',$attributes);

?>
<div class="form-group">
    <input type="email" class="form-control form-control-user" id="email" name="email" aria-describedby="emailHelp" placeholder="Enter Email Address...">
</div>

<button class="btn btn-primary btn-user btn-block" type="submit">Reset Password</button>

<?php echo form_close(); ?>

我的控制器

public function forget_password(){
    $email =$this->input->post('email');
    $result = $this->Authentication_model->check_email($email);

    if($result){

        $this->sendpassword($result);
        $this->session->set_flashdata('success','Password has been reset and has been sent to your email :'.$email);
        redirect('Authentication/view_forgot');

    }else{

        $this->session->set_flashdata('error','The email you entered was not found on our database');
        redirect('Authentication/view_forgot');
    }
}

public function sendpassword($result){
    date_default_timezone_set('GMT');
    $this->load->helper('string');
    $password= random_string('alnum', 16);
    $this->db->where('email', $result);
    $this->db->update('users', $password);
    $this->load->library('email');
    $this->email->from('cantreply@youdomain.com', 'Your name');
    $this->email->to($user->email);
    $this->email->subject('Password reset');
    $this->email->message('You have requested the new password, Here is you new password:'. $password);
    $this->email->send();
}

我的模特

function check_email($email){
    $this->db->select('*');
    $this->db->from('users');
    $this->db->where('email',$email);
    $this->db->limit(1);

    $query = $this->db->get();

    if($query ->num_rows()==1) {
        return $query->result();
    } else {
        return false;
    }
}

0 个答案:

没有答案