0

i have a problem in updating data in codeigniter. There's no error message but The data cannot be updated when i change the data name and click submit the button.

I'm new in CI so i cant really figure out where did i do wrong. can you help me?

thankyou in advance

my view (views/form/form_edit_bank.php)

<form action="<?php echo site_url('bankdatel/updatebank/'.$row_bank['idbank']);?>" method="post">
              <div class="box-body">
                <div class="form-group">
                  <label>Nama Bank: </label>
                  <input type="text" name="namabank" value="<?php echo $row_bank['namabank']?>">
                </div>
              </div>

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">Ubah</button>
              </div>
            </form>

controller (controllers/bankdatel.php)

public function editbank(){

        $this->load->model('model_bankdatel');
        $data['row_bank'] = $this->model_bankdatel->selectbank($this->uri->segment(2));

        $this->load->view('template/header');
        $this->load->view('form/form_edit_bank', $data);
        $this->load->view('template/footer');
    }


    public function updatebank(){

        $arrdata = array(
                'namabank' => $this->input->post('namabank')
            );

        $this->load->model('model_bankdatel');
        $this->model_bankdatel->updatebank($arrdata, $this->uri->segment(3));
        $this->session->set_flashdata('berkas', "<script>alert('Nama Bank Berhasil Diubah');</script>");
        redirect('bankdatel');
    }   

model (model/model_bankdatel.php)

public function updatebank($data, $id){
        $this->db->where('idbank', $id);
        $this->db->update('mt_bank', $data);
    }

    public function selectbank($id)
    {
        $this->db->where('idbank', $id);
        return $this->db->get('mt_bank')->row(); 
    }
1
  • Check if you are getting any value for $this->uri->segment(3) Commented Apr 4, 2019 at 4:19

1 Answer 1

0

Your form URL is site_url('bankdatel/updatebank/'.$row_bank['idbank']). It means 1 argument is passing to function. So get $bankid like this

public function updatebank($bankid){

    $arrdata = array(
            'namabank' => $this->input->post('namabank')
        );

    $this->load->model('model_bankdatel');
    $this->model_bankdatel->updatebank($arrdata, $bankid);
    $this->session->set_flashdata('berkas', "<script>alert('Nama Bank Berhasil Diubah');</script>");
    redirect('bankdatel');
}

And use return with update query in the model

return $this->db->update('mt_bank', $data);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.