在codeigniter

时间:2018-05-16 00:42:09

标签: php database codeigniter

我正在尝试在主表中插入用户的用户数据,并且需要使用发票表生成发票,更改状态为付款/未付款按钮。但是我的代码中存在一些问题,我无法理解。使用Mobile_no作为外键& Invoice_no为自动增量。表1执行正常,但在调用table-2错误之后。

Table-1 (ci_user) Table-2 (voucher

模型

// Get user detial by ID
    public function get_user_by_id($id){
        $query = $this->db->get_where('ci_users', array('id' => $id));
        return $result = $query->row_array();
    }

    //---------------------------------------------------
    // Edit user Record
    public function edit_user($data, $id){
        $this->db->where('id', $id);
        $this->db->update('ci_users', $data);
        return true;
    }

    //---------------------------------------------------
    // Get User Role/Group
    public function get_user_groups(){
        $query = $this->db->get('ci_user_groups');
        return $result = $query->result_array();
    }


      // Get voucher detial by Mobiele No
    public function get_voucher_by_mobile_no($mobile_no){
        $query = $this->db->get_where('voucher', array('mobile_no' => $mobile_no));
        return $result = $query->row_array();
        }

    // Edit voucher Record
    public function edit_user_voucher($data, $mobile_no){
        $this->db->where('mobile_no', $mobile_no);
        $this->db->update('voucher', $data);
        return true;
        }

控制器

public function edit($id = 0){
        if($this->input->post('submit')){
            $this->form_validation->set_rules('username', 'Username', 'trim|required');
            $this->form_validation->set_rules('firstname', 'Firstname', 'trim|required');
            $this->form_validation->set_rules('lastname', 'Lastname', 'trim|required');
            $this->form_validation->set_rules('email', 'Email', 'trim|valid_email|required');
            $this->form_validation->set_rules('mobile_no', 'Number', 'trim|required');
            $this->form_validation->set_rules('status', 'Status', 'trim|required');
            $this->form_validation->set_rules('address', 'Address', 'trim');
            $this->form_validation->set_rules('group', 'Group', 'trim|required');

            if ($this->form_validation->run() == FALSE) {
                $data['user'] = $this->user_working->get_user_by_id($id);
                $data['user_groups'] = $this->user_working->get_user_groups();
                $data['view'] = 'user/users/user_edit';
                $this->load->view('layout', $data);
            }
            else{
                $data = array(
                   'referred_by_id' => $this->session->userdata('referred_by_id'),
                    'name' => $this->session->userdata('sponcer_name'),
                    'username' => $this->input->post('username'),
                    'firstname' => $this->input->post('firstname'),
                    'lastname' => $this->input->post('lastname'),
                    'email' => $this->input->post('email'),
                    'mobile_no' => $this->input->post('mobile_no'),
                    'password' =>  password_hash($this->input->post('password'), PASSWORD_BCRYPT),
                    'role' => $this->input->post('group'),
                    'address' => $this->input->post('address'),
                    'is_active' => $this->input->post('status'),
                    'updated_at' => date('Y-m-d : h:m:s'),
                );
                $data = $this->security->xss_clean($data);
                $result = $this->user_working->edit_user($data, $id);
                if($result){
                    $this->session->set_flashdata('msg', 'User has been updated successfully!');
                    redirect(base_url('user/users'));
                }
            }
        }
        else{
            $data['user'] = $this->user_working->get_user_by_id($id);
            $data['user_groups'] = $this->user_working->get_user_groups();
            $data['view'] = 'user/users/user_edit';
            $this->load->view('layout', $data);
        }
    }
    //-----------------------------------------------------------------------
    public function del($id = 0){
        $this->db->delete('ci_users', array('id' => $id));
        $this->session->set_flashdata('msg', 'Use has been deleted successfully!');
        redirect(base_url('user/users'));
    }

0 个答案:

没有答案