bagaimana cara membuat sistem Ganti password pada codeigniter?

Controller

public function ganti_password()
    {
        $username = $this->session->userdata['username'];

        $this->form_validation->set_rules('pw_baru','password baru','required');
        $this->form_validation->set_rules('cpw_baru','password kedua','required|matches[pw_baru]');

        $this->form_validation->set_message('required','%s wajib diisi');

        $this->form_validation->set_error_delimiters('<p class="alert">','</p>');

        if( $this->form_validation->run() == FALSE ){
            $this->load->view('users/v_ganti_password');
        } else {
            $post = $this->input->post();

            $data = array(
                'password' => md5($post['pw_baru']),
            );

            $this->Post_model->update($username, $data['password'], 'tbuser');

        }

Views Ganti_password

<?php $data = $this->session->userdata(); ?>

        <img src="http://localhost/robot.png" alt="" width="200px">
        <br><br>
            <h1 style="color: #3399ff;">@<?= $data['username']; ?></h1>
        <br>

        <form action="<?= base_url('home/ganti_password'); ?>" method="POST">
            <hr>

            <br><br>

            <input type="text" name="password" class="inputan" placeholder="password" value="<?= $data['password']; ?>" readonly> <br><br>

            <input type="password" name="pw_baru"  class="inputan" placeholder="password baru">    <br>
            <?= form_error('pw_baru'); ?>

            <br>

            <input type="text" name="cpw_baru"  class="inputan" placeholder="ulangi password baru">  <br>
            <?= form_error('cpw_baru'); ?>

            <br>

            <input type="submit" name="submit" value="Ganti Password">
        </form>

POST MODEL :

 public function update($username,$data,$table)
    {
         //id apa yang mau di update, lalu DATA apa yang mau dikirim ke tabel di database
        $this->db->where('username',$username);
        $this->db->update($table,$data);
    }

ERROR :

Mohon bantu fix errornya gan..

avatar jhonyrain32
@jhonyrain32

196 Kontribusi 192 Poin

Diperbarui 7 tahun yang lalu

2 Jawaban:

Parameternya (username, data, table) yg dikirim $data['password'] , jd itu yg ke kirim string passwordnya dan disangka sbgai field yg ada di table, unknown field 55a86...... , coba yg diopper array datanya jangan passwordnya jd yg dioper di controller post_model->update($username, $data, $table)

Siapa tau bisa

avatar gunalirezqimauludi
@gunalirezqimauludi

350 Kontribusi 243 Poin

Dipost 7 tahun yang lalu

thanks gan, udah bisa :)

avatar jhonyrain32
@jhonyrain32

196 Kontribusi 192 Poin

Dipost 7 tahun yang lalu

Login untuk ikut Jawaban