更新两个表以生成发票并激活用户

时间:2018-06-06 09:28:11

标签: php database codeigniter-3

我需要在激活用户时生成发票,其中mobile_no在两个表中都是外键。 我有两个表需要更新如下

表1 CI_USER

is_active = 0/1    mobile_no

表2 VOUCHER

mobile_no voucher_no | Auto Increment voucher_date

voucher_amount reward1_amt reward2_amt    is_reward1

is_reward2 reward1_date reward2_date

但是我在功能或控制器方面遇到了一些问题,所以请为我提供任何解决方案

模型

public function edit_user($data, $id){
         $this->db->set($data);
         $this->db->where('ci_users.id', $id);
         $this->db->where( 'voucher.id', $id );       
         $this->db->update(array('ci_users as a', 'voucher as b'));
        return true;
    }

的Controler

public function activate($id = 0)($mobile_no = mobile_no){
        if($this->input->post('submit')){
            $this->form_validation->set_rules('voucher_amount', 'Voucher Amount', 'trim|required');
            $this->form_validation->set_rules('status', 'Status', 'trim|required');

            if ($this->form_validation->run() == FALSE) {
                $data['user'] = $this->Activate_member_model->get_user_by_id($id);
                $data['user_groups'] = $this->Activate_member_model->get_user_groups();
                $data['view'] = 'admin/Activate_member/member_edit';
                $this->load->view('layout', $data);
            }
            else{
                $data = array(
                    'mobile_no' => $this->session->userdata('mobile_no'),
                    'voucher_amount' => $this->input->post('voucher_amount'),
                    'is_active' => $this->input->post('status'),
                    'updated_at' => date('Y-m-d : h:m:s'),
                    'voucher_date' => date('Y-m-d : h:m:s'),
                    'voucher_no' => $this->input->post('voucher_no'),
                );
                $data = $this->security->xss_clean($data);
                $result = $this->Activate_member_model->edit_user($data, $id);
                if($result){
                    $this->session->set_flashdata('msg', 'User has been updated successfully!');
                    redirect(base_url('admin/Activate_member'));
                }
            }
        }
        else{
            $data['user'] = $this->Activate_member_model->get_user_by_id($id);
            $data['user_groups'] = $this->Activate_member_model->get_user_groups();
            $data['view'] = 'admin/Activate_member/member_edit';
            $this->load->view('layout', $data);
        }
    }

激活功能的第1行的短语问题1 Message: syntax error, unexpected '(', expecting ';' or '{' 如果像这样调用1个表正常工作

public function activate($id = 0){

}

问题2如果只使用($id = 0) Messege :' UPDATE数组SET mobile_no ='',voucher_amount =' 11000' ,is_active =' 1',updated_at =' 2018-06-06:07:06:19',voucher_date =&#39 ; 2018-06-06:07:06:19',voucher_no ='' ci_usersid =' 8'和voucherid =' 8'`

0 个答案:

没有答案