使用带有Codeigniter的Ajax无法更新

时间:2019-06-19 19:08:43

标签: php ajax codeigniter

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

模型

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

}

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

确保所有数据都可以正常使用,尤其是您的ID,然后像这样更新:

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