Php CodeIgniter数据插入不工作
在Codeigniter项目中,插入多个字段时,只有一个字段值没有插入到数据库中 用于计费的控制器代码Php CodeIgniter数据插入不工作,php,mysql,codeigniter,Php,Mysql,Codeigniter,在Codeigniter项目中,插入多个字段时,只有一个字段值没有插入到数据库中 用于计费的控制器代码 function billing() { $arrInsert =array(); $arrtoolsId =array(); $this->db_session->unset_userdata('tools_cart'); $arrtoolsId= $this->input->post('productId'); foreac
function billing()
{
$arrInsert =array();
$arrtoolsId =array();
$this->db_session->unset_userdata('tools_cart');
$arrtoolsId= $this->input->post('productId');
foreach ($arrtoolsId as $val) {
$arrToolrow = array();
$productExclusivePrice =0;
$arrToolrow =$this->product_model->getRow_products("gp.productId = '$val'");
$price =$arrToolrow['productPrice'];
$actual_price=$this->input->post('actual_price');
//$price =$this->input->post('price');
/////////////////////////////////////////////////////////////////////
$qty=1;
////////////////////////////////////////////////////
$variant ='';
$total = ($price * trim($qty));
$engineNo=$arrToolrow['engineNo'];
$vehicleClass =$arrToolrow['vehicleClass'];
$manufacturer =$arrToolrow['manufacturer'];
$model =$arrToolrow['model'];
//Note variant
$variant = $arrToolrow['hp'];
$vin = $arrToolrow['vin'];
$wcoNo = $arrToolrow['wcoNo'];
$horsePower =$arrToolrow['horsePower'];
$fuel =$arrToolrow['fuel'];
$noCylinders =$arrToolrow['noCylinders'];
$manufactureDate =$arrToolrow['manufactureDate'];
$seatCapacity =$arrToolrow['seatCapacity'];
$unladenWeight =$arrToolrow['unladenWeight'];
$frontAxle =$arrToolrow['frontAxle'];
$rearAxle =$arrToolrow['rearAxle'];
$otherAxle =$arrToolrow['otherAxle'];
$tandemAxle =$arrToolrow['tandemAxle'];
$color =$arrToolrow['color'];
$keyNo =$arrToolrow['keyNo'];
$grossVehicleWeight =$arrToolrow['grossVehicleWeight'];
$typeofBody =$arrToolrow['typeofBody'];
$productExclusivePrice=$arrToolrow['productExclusivePrice'];
$productTax = $arrToolrow['productTax'];
$saleExclusivePrice = ($productExclusivePrice * trim($qty));
$saleTax = ($arrToolrow['productTaxamt'] * trim($qty));
$saleCess = ($arrToolrow['productCess'] * trim($qty));
$arrInsert[] =array (
"productId" =>$val,
"engineNo"=>$engineNo,
"productPrice" =>round($price,2),
"productTax" =>$productTax,
"saleQty" =>$qty,
"salePrice" =>round($total,2),
"saleTax"=>round($saleTax,2),
"saleCess"=>round($saleCess,2),
"saleExclusiveprice"=>round($saleExclusivePrice,2),
"added_date" =>date("Y-m-d H:i:s"),
"vehicleClass" =>$vehicleClass,
"manufacturer" =>$manufacturer,
"model" =>$model,
"variant" =>$variant,
"vin" =>$vin,
"wcoNo" =>$wcoNo,
"horsePower" =>$horsePower,
"fuel" =>$fuel,
"noCylinders" =>$noCylinders,
"manufactureDate" =>$manufactureDate,
"seatCapacity" =>$seatCapacity,
"unladenWeight" =>$unladenWeight,
"frontAxle" =>$frontAxle,
"rearAxle" =>$rearAxle,
"otherAxle" =>$otherAxle,
"tandemAxle" =>$tandemAxle,
"color" =>$color,
"keyNo" =>$keyNo,
"grossVehicleWeight" =>$grossVehicleWeight,
"typeofBody" =>$typeofBody
);
}
$this->db_session->set_userdata('tools_cart',$arrInsert);
///////////////////////////////////////////////////////////////////////////////
$data['list_product']= $this->db_session->userdata('tools_cart');
$this->load->view('header_login');
$this->load->view('catalog/billing',$data);
$this->load->view('footer_login');
}
票据控制器代码(点击销售页面的票据按钮后)
未插入的错误字段或值字段
$actual_price=$this->input->post('actual_price');
哪个字段未存储?你能说得更具体些吗。代码似乎一次只存储一条记录,并且只有一个从post变量调用的值,我认为这就是问题所在。如果可以定义不存储的内容,将能够帮助您是否可以删除不相关的代码并仅显示精确的代码在中执行与数据库相关的操作model@raheelshan我已经从bill()中删除了不相关的代码($actual_price=$this->input->post('actual_price');上述字段即“实际价格”字段未更新。请将变量定义替换为$this->input->post(“实际价格”);如果不起作用,请检查该值是否存储在您维护的产品数组中。您好Kunal Kinalekar,我在db中的实际值为“0”。但我的问题是,当我在“实际价格”字段中输入值时,必须插入该值,但它对我无效。。我必须为此做些什么。?
function insert_sale_entry($data)
{
if($this->db->insert('gm_sale', $data)){
return true;
}
return false;
}
$actual_price=$this->input->post('actual_price');