挿入しません。 DBドライバ:mysqli Codeigniterを使用しています。CODEIGNITER Mysqlのデータベースに挿入しません
コントローラ
function add_quote()
{
$this->form_validation->set_rules('invoice_no', $this->lang->line("invoice_no"));
$this->form_validation->set_rules('date', $this->lang->line("date"), 'required');
$this->form_validation->set_rules('customer', $this->lang->line("customer"), 'required');
if($this->input->post('customer') == 'new') {
$this->form_validation->set_rules('state', $this->lang->line("state"));
$this->form_validation->set_rules('gstin', $this->lang->line("gstin"));
$this->form_validation->set_rules('company', $this->lang->line("company")." ".$this->lang->line("name"), 'required');
$this->form_validation->set_rules('email', $this->lang->line("customer")." ".$this->lang->line("email_address"), 'required|valid_email|is_unique[customers.email]');
$this->form_validation->set_rules('phone', $this->lang->line("phone"), 'required|min_length[6]|max_length[16]');
}
if ($this->form_validation->run() == true) {
print_r("helo World");
exit;
$form = $this->sales_model->process_form();
$customer_data = $form['customer_data'];
$products = $form['products'];
$data = $form['data'];
$dum = 'Q-'.$data['reference_no'];
$data['reference_no'] = $dum;
//unset($data['due_date'], $data['recurring']);
//echo '<pre />'; var_dump($data); var_dump($products); die();
}
//$data1 = array('reference_no' => 1);
//$this->db->insert('customers',$data1);
if ($this->form_validation->run() == true && $this->sales_model->addQuote($data, $products, $customer_data)) {
$this->session->set_flashdata('message', $this->lang->line("quote_added"));
redirect("sales/quotes");
} else {
$this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error'));
$this->data['inv'] = false;
$this->data['q'] = true;
$this->data['customers'] = $this->sales_model->getAllCustomers();
$this->data['tax_rates'] = $this->sales_model->getAllTaxRates();
$this->data['companies'] = $this->sales_model->getAllCompanies();
$this->data['page_title'] = $this->lang->line("new_quote");
$this->page_construct('sales/add_quote', $this->data);
}
}
モデル:
public function addQuote($data = array(), $items = array(), $customer = array()) {
if(!empty($customer)) {
if($this->db->insert('customers', $customer)) {
$customer_id = $this->db->insert_id();
}
$data['customer_id'] = $customer_id;
}
if($this->db->insert('quotes', $data)) { //Not inserted so Not enter into this loop
$quote_id = $this->db->insert_id();
foreach ($items as $item) {
$item['quote_id'] = $quote_id;
$this->db->insert('quote_items', $item);
}
return true;
}
else{
print_r("not inserted DATA");
exit;
}
return false;
}
配列結果:(ますprint_r($データ))
アレイ([reference_no] => Q-SMGP/17-18/000 003 [company_id] => 1 [SMGP] [vehicle_no] => dfg [date_time_supply] => 2017-07-15 12:17 [place_supply] => sdafsd [consignee_name] => safsdaf [consignee_address] => sdfsaf [日付] => 2017-07-15 12:17 [due_date] => [expiry_date] => 2017-07- [ユーザー] => 1 => 1 [顧客ID] => 3 [顧客名] =>シード・ライズ [total_tax] => 28.0000 [合計] => 2100 [grand_total] => 2600.0000 [ステータス] =>注文された[出荷] => 500.00 [メモ] =>)
あなたのモデル検証を確認してください。そこに検証エラーが表示される場合があります。 – urfusion
ifステートメント内の変数を定義していますが、変数が設定されているかどうかにかかわらず、ステートメントを使用しています。次に、それらが存在するかどうかをチェックせずに値を挿入しようとしています。エラーログを確認してください。 –
正確ではありません... Bcoz Form_validation()内でPrint_rを試してみました。それは完璧に機能します。 –