3
我對PHP很陌生,沒有出現錯誤但出現錯誤,無法更新數據庫中的數據。無法在codeigniter中更新我的數據庫記錄,沒有錯誤出現
public function update_user_view() {
$this->load->helper('form');
$user_id = $this->uri->segment('3');
$query = $this->db->get_where("users",array("user_id"=>$user_id));
$data['records'] = $query->result();
$data['old_user_id'] = $user_id;
$this->load->view('user_edit',$data);
}
public function update_user(){
$this->load->model('user_model');
$data = array(
'user_id' => $this->input->post('user_id'),
'name' => $this->input->post('name'),
'nickname' => $this->input->post('nickname'),
'email' => $this->input->post('email'),
'hadd' => $this->input->post('hadd'),
'gender' => $this->input->post('gender'),
'cpnum' => $this->input->post('cpnum'),
'comment' => $this->input->post('comment')
);
$old_user_id = $this->input->post('old_user_id');
$this->user_model->update($data,$old_user_id);
$query = $this->db->get("users");
$data['records'] = $query->result();
$this->load->view('user_view',$data);
}
<?php
class User_model extends CI_Model {
function __construct() {
parent::__construct();
}
public function insert($data) {
if ($this->db->insert("users", $data)) {
return true;
}
}
public function delete($user_id) {
if ($this->db->delete("users", "user_id = ".$user_id)) {
return true;
}
}
public function update($data,$old_user_id) {
$this->db->set($data);
$this->db->where("user_id", $old_user_id);
$this->db->update("users", $data);
}
}
?>
'echo $ this-> db-> last_query();'更新後,看看有什麼問題 –
@FastSnail什麼也沒有發生。 – jrpf
什麼都沒有?你應該看到實際的mysql查詢 –