Php 更新查询代码点火器消息
我正在运行更新查询以更新图书馆中的图书记录。现在的问题是,如何在更新成功后打印成功消息而不是更新成功Php 更新查询代码点火器消息,php,codeigniter,Php,Codeigniter,我正在运行更新查询以更新图书馆中的图书记录。现在的问题是,如何在更新成功后打印成功消息而不是更新成功 更新后,它将在空白页上重定向 我的模型是 function update_book($data, $id) { $this->load->database(); $this->db->where("id", $id); $query =$this->db->update("books", $data); if ($this->db-&g
更新后,它将在空白页上重定向 我的模型是
function update_book($data, $id)
{
$this->load->database();
$this->db->where("id", $id);
$query =$this->db->update("books", $data);
if ($this->db->affected_rows() > 0)
{
$response = array(
'message' => "User edited successfully",
'status' => true
);
}
else
$response = array(
'message' => "There is nothing to update",
'status' => false
);
return $response;
}
控制器为:
public function edit_info()
{
$id = $this->input->post('id');
$book_name = $this->input->post('book_name');
$book_author = $this->input->post('book_author');
$book_publisher = $this->input->post('book_publisher');
$book_pages = $this->input->post('book_pages');
$book_price = $this->input->post('book_price');
$book_stock = $this->input->post('book_stock');
$book_data = array(
'id'=>$id,
'book_name'=>$book_name,
'book_author'=>$book_author,
'book_publisher'=>$book_publisher,
'book_pages'=>$book_pages,
'book_price'=>$book_price,
'book_stock'=>$book_stock
);
$this->load->model('Book');
$result = $this->Book->update_book($book_data, $id);
if(in_array(1, $result))
{
$this->session->set_flash-data('MSG', 'Book Record Updated!!');
}
else
{
echo "FALSE";
}
}
像这样试试
型号
function update_book($data, $id)
{
$this->load->database();
$this->db->where("id", $id)
return $this->db->update("books", $data);
}
控制器
$this->load->model('Book');
$result = $this->Book->update_book($book_data, $id);
if($result){
$response = array(
'message' => "User edited successfully",
'status' => true
);
}else{
$response = array(
'message' => "There is nothing to update",
'status' => false
);
}
在重定向blank页面
echo$this->session->flashdata('MSG')代码>请告诉我们您的错误,您的问题不清楚
if($result['status'] == true){
echo $result['message'];
$this->session->set_flashdata('MSG', 'Book Record Updated!!');
}
else{
echo $result['message'];
}