I have three files that are attachments in an email. I am extracting them from the email using imap functions.
I need to add a record into a table with a flag to append the data from the second and third file extracted.
This is shortened code for the loop:
// default these values
$append = 'N';
$update_qtys = 'N';
for($i = 0; $i < count($attachments); $i++) {
// seperate the parts of the filename
$path_parts = pathinfo($attachments[$i]['filename']);
// default this value
$process = '0';
// rename the INV?.XLS files to TXT; only need to do this for this user_id
if($user_id=='75') {
if($path_parts['filename'] == 'INV1' ||
$path_parts['filename'] == 'INV2') {
$path_parts['extension'] = 'TXT';
}
$append = ($append=='N'?'Y':'N');
$process = 1;
} // if
// remove the directory from the filename
$filename = $user_id.'_'.$path_parts['filename'].'_'.date('m_d_Y').'.'.$path_parts['extension'];
// Now insert into file_upload table
$insert_sql = "INSERT INTO `file_upload` VALUES (NULL,$user_id, '$filename', {$process}, NOW(), '{$append}', '{$update_qtys}')";
$mysql_query($insert_sql) or die("Can't insert record:".mysql_error());
} // for
The result is that all three entries have the append = 'N' and I want the last two processd to have 'Y'. The first one
processed should have 'N'. What am I doing wrong here logically?