1

I tried this code but it does not work for me. i just want to add the array value to database. it give me error like this

Notice: Undefined offset: 2

Here is my code:

$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])");

}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

2 Answers2

0

The database requires a datatime in the format

2016-10-02 10:00:00

So change this

$timeadd = date("m-d-Y H:i:s", strtotime('+6 hours')); 

to

$timeadd = date("Y-m-d H:i:s", strtotime('+6 hours')); 
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
-1

Additionally to the other users I have removed the double brackets. What happens now?

$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]");
}
Philipp Palmtag
  • 1,310
  • 2
  • 16
  • 18