簡體   English   中英

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM