简体   繁体   English

无法更新 codeigniter 中的数据库记录

[英]unable to update the records of database in codeigniter

i have website in codeigniter and i want to update the records through the form.我在 codeigniter 有网站,我想通过表格更新记录。 i have fetched the data from database in a form after that i am updating what i have tried我已经以表格的形式从数据库中获取了数据,之后我正在更新我尝试过的内容

admin.php (controller) admin.php (控制器)


 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) updatemodel.php (型号)

<?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.您收到此错误是因为 controller 中的updatearticle()方法将$offer_id作为参数。 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) .将您的方法updatearticle($offer_id)更改为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.但是您必须在编辑表单中包含$offer_id作为输入字段,并在调用$this->updatemodel->update_article()方法时相应地访问它。

  2. Change you form action to admin/updatearticle/$offer_id .将您的表单操作更改为admin/updatearticle/$offer_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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