gpt4 book ai didi

php - 不在 CODEIGNITER Mysql 中插入数据库

转载 作者:搜寻专家 更新时间:2023-10-30 21:56:24 26 4
gpt4 key购买 nike

不插入..有什么建议吗??数据库驱动程序:mysqli使用 Codeigniter。

Controller

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($data))

Array ( [reference_no] => Q-SMGP/17-18/000003 [company_id] => 1 [company_name] => SMGP [vehicle_no] => dfg [date_time_supply] => 2017-07-15 12:17 [place_supply] => sdafsd [consignee_name] => safsdaf [consignee_address] => sdfsdaf [consignee_gstin] => 6556 [consignee_state] => sdfsa [consignee_state_code] => sdafaf [date] => 2017-07-15 12:17 [due_date] => [expiry_date] => 2017-07-15 [user] => 1 [user_id] => 1 [customer_id] => 3 [customer_name] => Seed Arise [total_tax] => 28.0000 [total] => 2100 [grand_total] => 2600.0000 [status] => ordered [shipping] => 500.00 [note] => )

最佳答案

检查表字段名称。由于使用错误的字段名称插入可能无法正常工作。

$this->db->last_query();

使用它来查找。它会给你插入的sql查询。在 phpmyadmin 中运行它。

关于php - 不在 CODEIGNITER Mysql 中插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45116074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com