php - How to upload image in codeigniter, Error Number: 1136 -
the controller want user can upload image database in table "invoices" or "orders" column "bukti_trnsfr" thanks
public function payment_confirmation($invoice_id = 0 ) { $data['get_sitename'] = $this->model_settings->sitename_settings(); $data['get_footer'] = $this->model_settings->footer_settings(); $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); $this->form_validation->set_rules('invoice_id_input','invoice id','required|integer'); $this->form_validation->set_rules('amount_input','amount transfered','required|integer'); if($this->form_validation->run() == false) { if($this->input->post('invoice_id_input')) { $data['invoice_id'] =set_value('invoice_id_input'); }else{ $data['invoice_id'] = $invoice_id; $upload_image = $this->upload->data(); $data_invoices = array( 'bukti_trnsfr' => $upload_image['file_name']); } $this->load->view('customer/form_payment_confirmation',$data); }else{ $is_valid = $this->model_customer->mark_invoice_paid_confirmed(set_value('invoice_id_input'),set_value('amount_input'),set_value('file_name')); if ($is_valid) { $this->session->set_flashdata('message','terima kasih, produk yang anda pesan akan segera kami proses'); redirect('customer/shopping_history'); }else{ $this->session->set_flashdata('error','jumlah nominal salah, silahkan coba lagi '); redirect('customer/payment_confirmation/'.set_value('invoice_id_input')); } } }
this model. public function mark_invoice_paid_confirmed($invoice_id,$amount,$bukti_trnsfr) {//check invoice $ret = true ; $data_invoices = $this->db->insert('invoices', $bukti_trnsfr); $is_invoice = $this->db->where('id',$invoice_id)->limit(1)->get('invoices'); if($is_invoice->num_rows() == 0 ) { $ret = $ret && false;
}else{//check amount $total = $this->db->select('sum(qty * price) total') ->where('invoice_id',$invoice_id) ->get('orders'); if($total->row()->total > $amount ) { $ret = $ret && false ; }else {//mark invoice paid $this->db->where('id',$invoice_id)->update('invoices',array('status'=>'confirmed')); } } return $ret; }
you forget upload image in code. use below mentioned lines upload image in codeigniter after validation runs true.
$this->upload->do_upload('file_name');
let me know if not works.
Comments
Post a Comment