Php 我能';t更新数据库Codeigniter中的数据
我无法更新数据库中的数据。我不知道发生了什么。请帮助我。按编辑按钮显示数据。但我无法编辑数据库中的数据 我已将代码张贴在下面: Controller.phpPhp 我能';t更新数据库Codeigniter中的数据,php,codeigniter,Php,Codeigniter,我无法更新数据库中的数据。我不知道发生了什么。请帮助我。按编辑按钮显示数据。但我无法编辑数据库中的数据 我已将代码张贴在下面: Controller.php public function ajax_update() { $data = array( 'placename' => $this->input->post('placename'), 'description' => $this->input-&g
public function ajax_update()
{
$data = array(
'placename' => $this->input->post('placename'),
'description' => $this->input->post('description'),
'tel' => $this->input->post('tel'),
'latitude' => $this->input->post('latitude'),
'longtitude' => $this->input->post('longtitude'),
'placetype_id' => $this->input->post('placetype_id'),
'province_id' => $this->input->post('province_id'),
);
$this->tblplace->update(array('placeid' => $this->input->post('placeid')), $data);
echo json_encode(array("status" => TRUE));
}
Modal.php
public function save($data)
{
$this->db->insert('tblplace', $data);
return $this->db->insert_id();
}
public function update($where, $data)
{
$this->db->update('tblplace', $data, $where);
return $this->db->affected_rows();
}
我可以从数据库中获取数据以显示在文本框中。但无法更新数据。我需要帮助。谢谢。您的控制器:
public function ajax_update()
{
//You should also check the post array.
$ajax_post_data = $this->input->post();
log_message('debug', 'Ajax Post Data Array:' . print_r($ajax_post_data, TRUE));
$placeid = $this->input->post('placeid');
$data = array(
'placename' => $this->input->post('placename'),
'description' => $this->input->post('description'),
'tel' => $this->input->post('tel'),
'latitude' => $this->input->post('latitude'),
'longtitude' => $this->input->post('longtitude'),
'placetype_id' => $this->input->post('placetype_id'),
'province_id' => $this->input->post('province_id'),
);
$this->load->model('tblplace');
$updte_status = $this->tblplace->update($placeid, $data);
if($updte_status == TRUE){
echo json_encode(array("status" => true));
} else {
echo json_encode(array("status" => false));
}
}
在模型中:
public function update($where, $data)
{
$this->db->where('id', $where)
->update('tblplace', $data);
log_message('debug', 'Last Update Query:' . print_r($this->db->last_query(), TRUE));
log_message('debug', 'Affected row count:' . print_r(count($this->db->affected_rows()), TRUE));
if ($this->db->affected_rows() === 1) {
return TRUE;
}else{
return FALSE;
}
}
希望这是明确的,它将帮助您更新数据 更新函数中没有
where
条件
public function update($where, $data)
{
$this->db->where($where);
$this->db->update('tblplace', $data);
return $this->db->affected_rows();
}
您是否能够从
ajax\u update()
方法上的post获取数据?模型中的where条件在哪里?检查$this->db->last\u query()
查找您的update
查询中发生的错误以及update
函数中缺少的参数。我可以按保存按钮,但不能更改数据更新。显示$post=$this->input->post()的值;var_出口(员额)代码>