skip to Main Content

I am having problems with my college assignments. I’m learning to make a update function trough codeigniter, then I got an error :

Missing argument 1 for Account::update()

When I press “Submit” button.

Controller :

class Account extends CI_Controller {

public function __construct() {
    parent::__construct();

    $this->load->model('cpanel/account/account_model');
}

public function update($nim) {
    $this->form_validation->set_rules('nim', 'nim', 'required');
    $this->form_validation->set_rules('nama', 'nama', 'required');
    $this->form_validation->set_rules('sandi', 'sandi', 'required');
    $this->form_validation->set_rules('email', 'email', 'required');
    $this->form_validation->set_rules('telp', 'telp', 'required');

    if ($this->form_validation->run() === FALSE) {
        $data['akun'] = $this->account_model->detail();
        $data['detail'] = $this->account_model->detail($nim);
        $data = array('title'=> 'Mengubah Data Akun : '.$data['detail']['ortu_nama'], 'akun'=> $this->account_model->detail(), 'detail'=> $this->account_model->detail($nim), 'isi'=>'cpanel/account/account_edit_view');

        $this->load->view('cpanel/layout/wrapper',$data);
    } else {
        $data = array(
            'ortu_nim_mhs' => $this->input->post('nim'),
            'ortu_nama' => $this->input->post('nama'),
            'ortu_email' => $this->input->post('email'),
            'ortu_telp' => $this->input->post('telp')
            );

        $this->account_model->update($data);
        $konten = array('title'=>'Perubahan Data Sukses', 'isi'=>'cpanel/account/success_view');
        $this->load->view('cpanel/layout/wrapper', $konten);
    }
}}

Model :

class Account_model extends CI_Model {

public function __construct() {
    $this->load->database();
}

public function update($data) {
    $this->db->where('ortu_nim_mhs', $data['ortu_nim_mhs']);
    return $this->db->update('user_ortu', $data);
}

public function detail($nim = FALSE) {
    if ($nim === FALSE) {
        $query = $this->db->get('user_ortu');
        return $query->result_array();
    }
    $query = $this->db->get_where('user_ortu', array('ortu_nim_mhs'=>$nim));
    return $query->row_array();
}}

2

Answers


  1. Try $data = array(); in model function

    public function update($data = array()) {
       $this->db->where('ortu_nim_mhs', $data['ortu_nim_mhs']);
       return $this->db->update('user_ortu', $data);
    }
    
    Login or Signup to reply.
  2. In your above code if you are submitting form with POST method than function argument is not required. Please check below.

    public function update() {
        // Your code
    }
    

    But in case if you submitting form with get method than you need to set data for validation first, like given below.

    public function update() {
        $this->form_validation->set_data($this->input->get());
        $this->form_validation->set_rules('nim', 'nim', 'required');
        $this->form_validation->set_rules('nama', 'nama', 'required');
        $this->form_validation->set_rules('sandi', 'sandi', 'required');
        $this->form_validation->set_rules('email', 'email', 'required');
        $this->form_validation->set_rules('telp', 'telp', 'required');
    
        // Your other code
    }
    

    This will help you. Let me know if it not works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search