【问题标题】:Not working update using ajax with codeigniter无法使用带有 codeigniter 的 ajax 进行更新
【发布时间】:2019-06-19 19:08:43
【问题描述】:

当我更新一列时,会更改所有列。 我该如何解决?

型号

public function update($where, $data)
{
    $this->db->update($this->table, $data, $where);
    return $this->db->affected_rows();
}

控制器:

public function ajax_update()
{

    $data = array(
            'book_title' => $this->input->post('book_title'),
            'book_isbn' => $this->input->post('book_isbn'),
            'book_yop' => $this->input->post('book_yop'),
            'book_active' => $this->input->post('book_active'),
            'publisher_name' => $this->input->post('publisher_name'),
            'author_name' => $this->input->post('author_name'),

        );

    $this->user_model->update( $this->input->post('book_id'), $data);
    echo json_encode(array("status" => TRUE));

}

【问题讨论】:

标签: php ajax codeigniter


【解决方案1】:

确保您的所有数据都正常,尤其是您的 id,然后像这样更新:

$this->db->where('book_id', $this->input->post('book_id'));
$this->db->update($this->table, $data);

【讨论】:

  • 我发现 $this->input->post('book_id') 为空。
  • 你没有从视图中正确传递,先解决这个问题。
  • 非常感谢。
【解决方案2】:

基于CodeIgniter documentation,我建议更改定义“where”部分的代码:

 $this->user_model->update( array('book_id' => $this->input->post('book_id')), $data);

【讨论】:

  • 我试了一下,但没有更新,也没有错误消息。
猜你喜欢
  • 1970-01-01
  • 2019-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-01
  • 2016-03-19
  • 2017-10-18
相关资源
最近更新 更多