I've not found an answer to my question, nor have I seen anyone ask this particular question. I have a php purchase order form where I dynamically add line items via javascript and am able to capture all data for each line item in an array and post the data to a mysql database. The only field I am having issues with is the required by date.
I generally use date(strtotime()) to convert a date such as 01/01/01 to 2001-01-01 for purposes of storing in mysql however I am unable to properly capture this date, reformat to an appropriate datetime string and then post with my other data by iterating through my array.
In my haste I've tried a number of different approaches such as putting the date("Y-m-d",strtotime($Item_Date[$a])) within my INSERT Query along with declaring a variable and assigning date("Y-m-d",strtotime($Item_Date[$a])) with the thought of that value being reassigned with each pass through my foreach loop. Examples of each mentioned attempt are outlined below.
EXAMPLE 1
foreach($Cust_PN as $a => $b) {
$query1 = "INSERT INTO SO_Items (Timestamp,SO_Num,SO_Rev,SO_Line_Item,Cust_PN,Cust_PN_Rev,E3_PN,E3_PN_Rev,Description,
Qty,Sale_Price,UOM,Program,Required_Date)
SELECT NOW(),'$SO_Num','$SO_Rev','$i','$Cust_PN[$a]','$Cust_PN_Rev[$a]','$PN[$a]','$PN_Rev[$a]','$Description[$a]','$Qty[$a]','$Sale_Price[$a]','$UOM[$a]','$Program[$a]','date("Y-m-d", strtotime($Item_Date[$a]))'" or die ('Error posting data');
mysql_query($query1);
$i++;
}
EXAMPLE 2
foreach($Cust_PN as $a => $b) {
$query1 = "INSERT INTO SO_Items (Timestamp,SO_Num,SO_Rev,SO_Line_Item,Cust_PN,Cust_PN_Rev,E3_PN,E3_PN_Rev,Description,
Qty,Sale_Price,UOM,Program,Required_Date)
SELECT NOW(),'$SO_Num','$SO_Rev','$i','$Cust_PN[$a]','$Cust_PN_Rev[$a]','$PN[$a]','$PN_Rev[$a]','$Description[$a]','$Qty[$a]','$Sale_Price[$a]','$UOM[$a]','$Program[$a]','$Item_Date[$a]'" or die ('Error posting data');
$Item_Date = date("Y-m-d", strtotime($Item_Date[$a]));
mysql_query($query1);
$i++;
}
Any assistance would be much appreciated.