在Codeigniter项目中,插入多个字段时,只有一个字段值未插入数据库中。
帐单控制器代码
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');
}
帐单的控制器代码(点击销售页面的帐单按钮后)
function bill()
{
if($this->db_session->userdata('tools_cart')) {
$data['list_product']= $this->db_session->userdata('tools_cart');
}else{
redirect('catalog/sale');
}
$salePrice = $this->input->post('price');
$actual_price=$this->input->post('actual_price');
////////////////////////////////////////////////////////////CHANGE HERE
$saleExclusiveprice = ($salePrice * 100) / 114.5;
///////////////////////////////////////////////////////////THIS CAN CHANGE EVERY YEAR
//$saleTax = $saleExclusiveprice *(14.5/100);
//checking tax value with the current date...........
$arrtax = $this->tax_model->getTaxList();
foreach($arrtax as $taxvalue) :
$currdate =$this->input->post('sale_date') ;
if(($taxvalue['fromdate']<=$currdate)&&($currdate<=$taxvalue['todate']))
{
// print_r($taxvalue['tax']);
$saleTax = $saleExclusiveprice *($taxvalue['tax']/100);
$data['list_product'][0]['taxvalue'] = $taxvalue['tax'];
}
endforeach;
//$saleCess = $saleTax*(1/100); //ORIGINALLY USED IN 2011
$saleCess = 0;
$data['list_product'][0]['salePrice'] = $salePrice;
$data['list_product'][0]['saleExclusiveprice'] = round($saleExclusiveprice,2);
$data['list_product'][0]['saleTax'] = round($saleTax,2);
$data['list_product'][0]['saleCess'] = round($saleCess,2);
$data['list_product'][0]['actual_price']=$this->input->post('actual_price');
$scheme_id =serialize($arrtoolsId);
$arrInsert =array (
"productId" =>$value['productId'],
"saleCode" =>$saleCode,
"saleQty" =>$value['saleQty'],
"salePrice" => $value['salePrice'],
"saleTax" => $value['saleTax'],
"saleCess" => $value['saleCess'],
"taxable_price" =>$taxable_price,
"nontaxable_price" =>$nontaxable_price,
"saleExclusiveprice" => $value['saleExclusiveprice'],
"saleCustomer"=>$saleCustomer,
"saleUserId"=>$this->input->post('saleUserId'),
"added_date" =>$date,
"payType"=>$pay_type,
"bank_id"=>$bank_id,
"consultant_id"=>$consultant_id,
"scheme_id"=>$scheme_id,
"schemes_amount" => $total,
"actual_price" =>$actual_price
);
$saleId=0;
if($this->product_model->insert_sale_entry($arrInsert)){
$saleId = $this->db->insert_id() ;
$arrStatus =array (
"productSaleStatus" =>1
);
$this->product_model->update_entry($arrStatus,$productId);
}
}
$query = $this->db->get_where('gm_users',array('userId'=>(int)$this->input->post('saleUserId')));
if($query->num_rows >0) {
$arrUser =$query->row_array();
}else{
$arrUser =array();
}
/*******************************************************************************/
$this->db_session->unset_userdata('tools_cart');
$data['arrtoolsId'] = $arrtoolsId;
$data['saleCustomer'] =$saleCustomer;
$data['saleCode'] =$saleCode;
$data['saleId'] =$saleId;
$data['saleDate'] =$date;
$data['userinfo'] =$arrUser;
$data['bank'] = $bank;
$data['scheme'] = $schemeName;
$data['wcoNo'] =$wcoNo;
$data['actual_price'] =$actual_price;
$this->load->view('header_login');
$this->load->view('catalog/bill',$data);
$this->load->view('footer_login');
}
我尝试了很多方法,但它不起作用。我在Dot net mvc上有实践经验,但它是我在codeigniter中的开始项目。我想知道数据流如何在这里工作以及如何解决这个问题?是否有我做过的任何逻辑错误?
型号代码
function insert_sale_entry($data)
{
if($this->db->insert('gm_sale', $data)){
return true;
}
return false;
}
错误字段或未插入的值字段
$actual_price=$this->input->post('actual_price');
答案 0 :(得分:1)
哪个字段没有存储?你可以说得更详细点吗。代码似乎一次存储一条记录,只有一个值从post变量调用是我认为的问题。如果您可以定义什么不存储
,将能够帮助您