douzhi2988 2013-12-12 09:08
浏览 48
已采纳

CodeIgniter数据插入不起作用

In Codeigniter project ,when inserting multiple fields only one field value is not inserting in the database.

Controller Code For Billing

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');
}

Screenshot1

Controller Code for Bill(After clicking bill button of the sale page)

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');   
}

I have tried many ways, but its not working.I have hands on experience in Dot net mvc,but its my starting project in codeigniter.I want to know how the data flow works here and how to solve this?Is there any logical mistake i have done?

Model Code

 function insert_sale_entry($data)
{
   if($this->db->insert('gm_sale', $data)){
     return true;
   }
  return false;
}

The error field or the value field which is not inserting

$actual_price=$this->input->post('actual_price');
  • 写回答

1条回答 默认 最新

  • douyan8070 2013-12-12 10:23
    关注

    Which field is not stored ? can you be more specific. The code appears to store one record at a time and there is only one value which is called from the post variable is what i believe is the problem. Will be able to help you if you can define what is not storing

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改