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

时间:2020-07-06 20:35:39

标签: php codeigniter

我在codeigniter中拥有网站,我想通过表格更新记录。我在更新后以某种形式从数据库中获取了数据 我尝试过的事情

admin.php (控制器)

GridSearchCV

updatemodel.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);
  }

我遇到的错误

<?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);

}

}

做什么?

1 个答案:

答案 0 :(得分:0)

您收到此错误,因为控制器中的updatearticle()方法将$offer_id作为参数。提交编辑表单时,您可能会收到此错误。

要解决此问题,您可以:

  1. 将方法updatearticle($offer_id)更改为updatearticle($offer_id=NULL)。这样,即使您不传递参数,方法也将具有参数的默认值。但是您将必须在编辑表单中包括$offer_id作为输入字段,并在调用$this->updatemodel->update_article()方法时相应地对其进行访问。

  2. 将表单操作更改为admin/updatearticle/$offer_id

相关问题