使用带有 codeigniter 的 ajax 无法进行更新

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


模型


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


}


慕的地8271018
浏览 175回答 2
2回答

墨色风雨

确保您的所有数据都正常,尤其是您的 id,然后像这样更新:$this->db->where('book_id', $this->input->post('book_id'));$this->db->update($this->table, $data);

慕容森

根据CodeIgniter 文档,我建议更改定义“where”部分的代码: $this->user_model->update( array('book_id' => $this->input->post('book_id')), $data);
打开App,查看更多内容
随时随地看视频慕课网APP