为了账号安全,请及时绑定邮箱和手机立即绑定

使用 ajax 更新不适用于数据表和 codeigniter

使用 ajax 更新不适用于数据表和 codeigniter

PHP
慕码人8056858 2021-08-27 10:01:44
我的更新不起作用,但我在其网站上使用了相同的代码。 https://mbahcoding.com/tutorial/php/codeigniter/codeigniter-ajax-crud-modal-server-side-validation.html我在网络预览中的更新 chrome网络预览中的示例网站更新 chrome这是关于网络响应的 ajax 更新。 我尝试了正常的方法,但总是有错误。控制器...... 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));}模型..........public function update_book($data, $where){           $this->db->update('books',$data,$where);         return $this->db->affected_rows();}如果我 print_r($data); 吹是结果。我认为我的问题是数据没有传递到数据库。
查看完整描述

1 回答

?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

您的更新调用参数被反转。根据您的update_book模型函数,第一个参数是要更新的数据数组,第二个参数是 where 数组。然而,在这里$this->user_model->update_book(array('book_id' => $this->input->post('book_id')), $data);你首先有你的位置,第二个是数据。

它应该是:

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



查看完整回答
反对 回复 2021-08-27
  • 1 回答
  • 0 关注
  • 130 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信