Using ajax to update is not working on data-table and codeigniter

Viewed 149

!My update is not working but I using the same code in its website. https://mbahcoding.com/tutorial/php/codeigniter/codeigniter-ajax-crud-modal-server-side-validation.html

My update chrome in the network preview

enter image description here.

sample website update chrome in the network preview

enter image description here.

Here is ajax update on network response. enter image description here

I try normal way to do it but always have an error.

controller......

 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'),
            'author_name' => $this->input->post('author_name'),
             'publisher_name' => $this->input->post('publisher_name'),
        );
  $this->user_model->update_book(array('book_id' => $this->input->post('book_id')), $data);
    echo json_encode(array("status" => TRUE));

}

model..........

public function update_book($data, $where)
{    

       $this->db->update('books',$data,$where);
         return $this->db->affected_rows();

}

If I print_r($data); blew is the result. I think my issue is data is not passed to the database. enter image description here

1 Answers

Your update call parameters are reversed. According to your update_book model function the first parameter is the array of data to update, and the second parameter is the where array. However here $this->user_model->update_book(array('book_id' => $this->input->post('book_id')), $data); you have your where first and data second.

It should be:

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