成功提交表单,但控制台出现一个错误,例如发生数据库错误错误号:1048 - Codeigniter
Posted
技术标签:
【中文标题】成功提交表单,但控制台出现一个错误,例如发生数据库错误错误号:1048 - Codeigniter【英文标题】:Successfully submitted form but one error in console, like A Database Error Occurred Error Number: 1048 - Codeigniter 【发布时间】:2020-02-19 00:41:30 【问题描述】:当我成功提交表单并在表格中插入所有数据时,并且在控制台中出现如下错误,代码有问题吗?,我发现错误中的日期异常,日期显示为 '1970- 01-01'。但是我选择了今天的日期,但错误地只显示了“1970-01-01”;
A Database Error Occurred
Error Number: 1048
Column 'purchase_shopId' cannot be null
INSERT INTO `stock_purchase_history` (`purchase_shopId`, `purchase_productID`, `purchase_quantity`, `purchase_costPrice`, `purchase_TotalRate`, `purchase_tax`, `purchase_taxEmp`, `purchase_sellingPrice`, `purchase_employeeSellingPrice`, `purchase_supplierName`, `purchase_invoice`, `purchase_PurchaseDate`) VALUES (NULL, NULL, NULL, NULL, 0, NULL, NULL, 0, 0, NULL, NULL, '1970-01-01')
Filename: C:/xampp/htdocs/stock/system/database/DB_driver.php
Line Number: 691
我的查询代码
public function insertPurchaseData()
$shopId = $this->input->post('shopId');
$productID = $this->input->post('productID');
$quantity = $this->input->post('quantity');
$costPrice = $this->input->post('costPrice');
$PurchaseTotalRate = $quantity*$costPrice;
$taxNormal = $this->input->post('taxNormal');
$taxEmp = $this->input->post('taxEmp');
$supplierName = $this->input->post('supplierName');
$invoice = $this->input->post('invoice');
$PurchaseDate = date('Y-m-d', strtotime($this->input->post('PurchaseDate')));
// normal Selling price
$sellingPrice=($costPrice*$taxNormal)/100+$costPrice ;
// emp selling price
$employeeSellingPrice=($costPrice*$taxEmp)/100+$costPrice;
$purchaseData =array(
'purchase_shopId' => $shopId,
'purchase_productID' => $productID,
'purchase_quantity' =>$quantity,
'purchase_costPrice' =>$costPrice,
'purchase_TotalRate' =>$PurchaseTotalRate,
'purchase_tax' =>$taxNormal,
'purchase_taxEmp' =>$taxEmp,
'purchase_sellingPrice' =>$sellingPrice,
'purchase_employeeSellingPrice'=>$employeeSellingPrice,
'purchase_supplierName' =>$supplierName,
'purchase_invoice' =>$invoice,
'purchase_PurchaseDate' =>$PurchaseDate
);
$this->db->insert('stock_purchase_history',$purchaseData);
看下面的ajax代码
if(result == '1234567')
$.ajax(
type: "POST",
url: "<?php echo site_url('Con_purchase/add_purchase_for_shop')?>",
dataType: "JSON",
data:
shopId: shopId,
productID: productID,
quantity: quantity,
costPrice : costPrice ,
taxNormal : taxNormal ,
taxEmp : taxEmp ,
supplierName : supplierName,
invoice : invoice ,
PurchaseDate : PurchaseDate
,
success: function(data)
if (data == '1')
var btn = $(this).closest("tr")
var name = inputData.find("button").prop('disabled', false).css(
"background-color", "green");
else
var btn = $(this).closest("tr")
var name = inputData.find("button").prop('disabled', true).css(
"background-color", "#2d7bf4");
);
return false;
我的数据库 enter image description here
【问题讨论】:
var_dump 您的 post 数组并检查您的数据是否正确传递给控制器。 var_dump($this->input->post()); 【参考方案1】:您必须将列结构更改为 null 'purchase_shopId'
,因为您已选中了 null 复选框。
【讨论】:
【参考方案2】:“purchase_shopId”列不能为空,您可以在数据库中更改“purchase_shopId”可以为空。
ALTER TABLE `MyTable`
ALTER COLUMN `purchase_shopId` varchar(20)
DEFAULT NULL
【讨论】:
以上是关于成功提交表单,但控制台出现一个错误,例如发生数据库错误错误号:1048 - Codeigniter的主要内容,如果未能解决你的问题,请参考以下文章