它说“错误:列'DeliveredDate'不能为空。”
$delivereddate = null;
$stmt = $connection->prepare("INSERT INTO orders (receiptid, date, cid, cardno, expirydate, expecteddate, delivereddate) VALUES (?,?,?,?,?,?,?)");
$stmt->bind_param("sssssss", $receiptid, $date, $cid, $cardno, $expirydate, $expecteddate, $delivereddate);
相关表格是:
CREATE TABLE Orders(
ReceiptId char(30) not null,
Date date not null,
CId char(30) not null,
CardNo char(30) not null,
ExpiryDate date not null,
ExpectedDate date not null,
DeliveredDate date,
PRIMARY KEY(ReceiptId));
我尝试在mysql workbench中插入值,我可以这样做:
INSERT INTO orders VALUE
(1, '2012-12-10', 1, 1, '2014-2-3', '2012-12-23', null);
答案 0 :(得分:1)
试试这个
$delivereddate = '2014-11-26 10:40:35'; // some date
$stmt = $connection->prepare("INSERT INTO orders (receiptid, date, cid, cardno, expirydate, expecteddate, delivereddate) VALUES (?,?,?,?,?,?,?)");
$stmt->bind_param("sssssss", $receiptid, $date, $cid, $cardno, $expirydate, $expecteddate, $delivereddate);
我认为该错误是由$delivereddate = null;
评论错误......
答案 1 :(得分:1)
只需将您的表格sql
更改为允许NULL
列的DeliveryDate
。
CREATE TABLE Orders(
ReceiptId char(30) not null,
Date date not null,
CId char(30) not null,
CardNo char(30) not null,
ExpiryDate date not null,
ExpectedDate date not null,
DeliveredDate date null,
PRIMARY KEY(ReceiptId));
剩下的应该有效。 (如果您希望在该列中存储null
)