使用codeigniter将数据插入数据库 [英] insert data into database with codeigniter
问题描述
尝试使用CodeIgniter在我的数据库中插入一行。
我的数据库表为 Customer_Orders
是 CustomerName
和 OrderLines
。正在提交正确的变数。
我的控制器是(sales.php):
function new_blank_order_summary()
{
$ data = array(
'OrderLines'=> $ this-> input-> post('orderlines'),
'CustomerName'=> $ this-> input-> post('customer')
);
$ this-> sales_model-> order_summary_insert($ data);
$ this-> load-> view('sales / new_blank_order_summary');
}
我的模型是(sales_model.php):
function order_summary_insert($ data){
$ this-> db-> insert('Customer_Orders',$ data);
}
视图正确加载时,没有数据插入数据库。 p>
有什么想法?为什么不呢?
提前感谢。
function order_summary_insert()
$ OrderLines = $ this-> input-> post('orderlines');
$ CustomerName = $ this-> input-> post('customer');
$ data = array(
'OrderLines'=> $ OrderLines,
'CustomerName'=> $ CustomerName
);
$ this-> db-> insert('Customer_Orders',$ data);
}
尝试使用控制器来控制视图和模型总是将您的值模型。它使得容易理解。
你的控制器将是
function new_blank_order_summary(){
$ this-> sales_model-> order_summary_insert($ data);
$ this-> load-> view('sales / new_blank_order_summary');
}
Trying to insert a row into my database with CodeIgniter.
my database table is Customer_Orders
and the fields are CustomerName
and OrderLines
. The variables are being submitted correctly.
My Controller is(sales.php):
function new_blank_order_summary()
{
$data = array(
'OrderLines'=>$this->input->post('orderlines'),
'CustomerName'=>$this->input->post('customer')
);
$this->sales_model->order_summary_insert($data);
$this->load->view('sales/new_blank_order_summary');
}
My Model is(sales_model.php):
function order_summary_insert($data){
$this->db->insert('Customer_Orders',$data);
}
Whilst the view loads correctly, no data is inserted into the database.
Any ideas as to why not?
Thanks in advance.
try this in your model.
function order_summary_insert()
$OrderLines=$this->input->post('orderlines');
$CustomerName=$this->input->post('customer');
$data = array(
'OrderLines'=>$OrderLines,
'CustomerName'=>$CustomerName
);
$this->db->insert('Customer_Orders',$data);
}
try to use controller just to control the view and models always post your values in model. it makes easy to understand. you controller will be
function new_blank_order_summary() {
$this->sales_model->order_summary_insert($data);
$this->load->view('sales/new_blank_order_summary');
}
这篇关于使用codeigniter将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!