简体   繁体   中英

unable to update the records of database in codeigniter

i have website in codeigniter and i want to update the records through the form. i have fetched the data from database in a form after that i am updating what i have tried

admin.php (controller)


 public function updatearticle($offer_id)
 {
if($this->form_validation->run('upload_validation'))
  {
      $post=$this->input->post(); 
      //$articleid=$post['article_id'];
      //unset($articleid);
      $this->load->model('updatemodel');
      if($this->updatemodel->update_article($offer_id,$post))
      {
         $this->session->set_flashdata('insertsuccess','Article Update successfully');
          $this->session->set_flashdata('msg_class','alert-success');
      }
      else
      {
         $this->session->set_flashdata('insertsuccess','Articles not update Please try again!!');
         $this->session->set_flashdata('msg_class','alert-danger');
      }
      return redirect('admin/offerfetch');
     }
  else
  {
    $this->editoffer($offer_id);
  }

updatemodel.php (model)

<?php

class updatemodel extends CI_Model
{

            public function update_article($offer_id,Array $offers)
            {
  
                return $this->db->where('offer_id',$offer_id)
                 ->update('offers',$offers);

}

}

the error i have got

An uncaught Exception was encountered
Type: ArgumentCountError

Message: Too few arguments to function admin::updatearticle(), 0 passed in C:\xampp\htdocs\blog\system\core\CodeIgniter.php on line 532 and exactly 1 expected

Filename: C:\xampp\htdocs\blog\application\controllers\admin.php

Line Number: 128

Backtrace:

File: C:\xampp\htdocs\blog\index.php
Line: 315
Function: require_once

what to do???

You are getting this error because updatearticle() method in your controller takes $offer_id as parameter. And you are probably getting this error when you submit your edit form.

To solve the problem you can either:

  1. Change your method updatearticle($offer_id) to updatearticle($offer_id=NULL) . This way your method will have a default value of the parameter even when you don't pass one. But you will have to include $offer_id in your edit form as an input field and access it accordingly when calling $this->updatemodel->update_article() method.

  2. Change you form action to admin/updatearticle/$offer_id .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM