我试过这段代码,但它对我不起作用。我只想将数组值添加到数据库中。它给我这样的错误
注意:未定义的偏移量:2
这是我的代码:
$timeadd = date("m-d-Y H:i:s", strtotime('+6 hours'));
$extinvoice=mysqli_query($link,"Select * from invoice WHERE BRANCH_CODE_MX='".$display_branchcode."' and INVOICE_NO_MX='".$invoicecode."' and INVOICE_ITEM_UNIT_MX='EXTENDEDWARRANTY'");
while($extrow=mysqli_fetch_array($extinvoice))
{
$ewtitemcode=$extrow["INVOICE_ITEM_CODE_MX"];
$imeiserialunit=$extrow["EWT_IMEI_MX"];
$customercode=$extrow["INVOICE_CUS_CODE_MX"];
$ewtarray[] = "('$invoicecode','$ewtitemcode', '$imeiserialunit','$customercode','$display_branchcode','$timeadd')";
}
$arrayitem=count($ewtarray);
for($item = 0; $item <= $arrayitem; $item++)
{
$sql = mysqli_query($link,"INSERT INTO extended_warranty
(INVOICE_NO_MX,FORM_EW_MX,EW_SERIAL_MX,CUSTOMER_CODE,BRANCH_CODE_MX,DATE_ADDED)
VALUES
($ewtarray[$item])");
}
答案 0 :(得分:1)
数据库需要格式为
的数据时间2016-10-02 10:00:00
所以改变这个
$timeadd = date("m-d-Y H:i:s", strtotime('+6 hours'));
到
$timeadd = date("Y-m-d H:i:s", strtotime('+6 hours'));
答案 1 :(得分:-1)
除了其他用户,我删除了双括号。现在发生了什么?
$timeadd = date("Y-m-d H:i:s", strtotime('+6 hours'));
$extinvoice=mysqli_query($link,"Select * from invoice WHERE BRANCH_CODE_MX='".$display_branchcode."' and INVOICE_NO_MX='".$invoicecode."' and INVOICE_ITEM_UNIT_MX='EXTENDEDWARRANTY'");
while ($extrow=mysqli_fetch_array($extinvoice)) {
$ewtitemcode=$extrow["INVOICE_ITEM_CODE_MX"];
$imeiserialunit=$extrow["EWT_IMEI_MX"];
$customercode=$extrow["INVOICE_CUS_CODE_MX"];
$ewtarray[] = "('$invoicecode','$ewtitemcode', '$imeiserialunit','$customercode','$display_branchcode','$timeadd')";
}
for ($item = 0; $item < count($ewtarray); $item++) {
$sql = mysqli_query($link,"INSERT INTO extended_warranty
(INVOICE_NO_MX,FORM_EW_MX,EW_SERIAL_MX,CUSTOMER_CODE,BRANCH_CODE_MX,DATE_ADDED)
VALUES
$ewtarray[$item]");
}