Codeigniter:更新功能未将数据更新到数据库中

时间:2016-05-26 06:47:20

标签: php codeigniter

来自视图的数据在更新功能之前准确显示,但未更新到数据库中。

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');
}

1 个答案:

答案 0 :(得分:-1)

您需要将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"
        );