![](/img/trans.png)
[英]How to Fix My Form Didn't Update Data to Database [Codeigniter]
[英]Codeigniter : Update function didn't update data into database
來自視圖的數據會在更新功能之前准確顯示,但不會更新到數據庫中。
Public Function update_visitor_after_post( $v_id = null , $u_id = null){
if($v_id = null || $u_id = null) {
redirect(site_url() . 'visitorcontroller/edit_visitor');
} else {
$name = $this->input->post('name');
$father_name = $this->input->post('father_name');
$purpose = $this->input->post('purpose');
$contact = $this->input->post('contact');
$country = $this->input->post('country');
$province = $this->input->post('province');
$city = $this->input->post('city');
$address = $this->input->post('address');
$note = $this->input->post('note');
$updated_at = mdate("%y-%m-%d");
$update_users_table = $this->db->update('users',
[
'name' => $name,
'father_name' => $father_name,
'contact' => $contact,
'fkcountry_id' => $country,
'fkstate_id' => $province,
'fkcity_id' => $city,
'updated_at' => $updated_at
],['u_id' => $u_id]
);
$update_visitors_table = $this->db->update('visitors',
[
'address' => $address,
'purpose' => $purpose,
'note' => $note,
'updated_at' => $updated_at
],['v_id' => $v_id]
);
}
redirect(site_url() . 'visitorcontroller/view_visitor');
}
您需要將where條件更改為字符串,如下所示
$update_users_table = $this->db->update('users',
[
'name' => $name,
'father_name' => $father_name,
'contact' => $contact,
'fkcountry_id' => $country,
'fkstate_id' => $province,
'fkcity_id' => $city,
'updated_at' => $updated_at
], "u_id = $u_id"
);
$update_visitors_table = $this->db->update('visitors',
[
'address' => $address,
'purpose' => $purpose,
'note' => $note,
'updated_at' => $updated_at
],"v_id = $v_id"
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.