This function is to preview an entry before it is submitted, my problem is when I'm uploading more than 1 new photos to a past (edited) entry (that is the only time it delves into the if statement). The line with the if statement containing the in_array function like it is will produce only the side that is uploading a new image with $temp_uploads variable. However if I inverse it to '!== false' then it only gets all the ones from the db, no matter how many times it's looped. I need it to work like it should and actually use the if...else statement.
function preview($page, $edit_id) {
global $db, $temp_uploads, $uploads;
$table = $db.$page;
$fields = array_merge($_POST, $_FILES);
$preview_form .= '<div class="white"></br><form enctype="multipart/form-data" action="?p='.$page.'&z=s&i='.$edit_id. '" method="post"><table class="preview" align="center">';
//loop through each field in the array
foreach($fields as $field => $value){
//if field's value has something special that needs to be done to it EX. upload an image.
if (strpos($field, "|") !== false) {
require_once('extra.php');
list($possible, $detail) = explode("|", $field);
$field = $possible;
if (strpos($detail, ";") !== false){
$get_details = explode(";", $detail);
//select field from table with id number from select input
if($get_details[0] == 'Fetch_select'){
$detail = 'id'.substr($detail, 12);
$fetch = detail('Fetch_preview', $detail, $value, $page, $header=false, $row['id']);
$preview_form .= '<tr><td><strong>'.format($field).':</strong></br>'.$fetch.'</td></tr><input type="hidden" value="'.$value.'" name="'.$field.'" />';
}
}
//upload a tmp image on a new entry (no id)
if(($detail == "Upload_tmp") && (!is_numeric($edit_id))){
$value = detail($detail, $field."|".$detail, $field, $page, null, $edit_id);
$preview_form .= '<tr><td><strong>'.format($field).':</strong></br>';
if($value !=''){
$preview_form .= '<img src="'.$temp_uploads.$value.'" /><input type="hidden" value="'.$value.'" name="'.$field.'|'.$detail.'_move" />';
}
$preview_form .= '</td></tr>';
//upload new image to a past entry (editing with id)
} else if(($detail == "Upload_tmp") && (is_numeric($edit_id))){
$table = $db.$page;
$get = @mysql_query('SELECT '.$field.' FROM `'.$table.'` WHERE `id` = '.$edit_id.' LIMIT 1');
$num = @mysql_num_rows($get);
$row = @mysql_fetch_array($get);
$edit_image = $row[$field];
$edit_image_short = substr($edit_image, 41);
$preview_form .= '<tr><td><strong>'.format($field).':</strong></br>';
//check whether field from db is being posted if it isn't then upload it
if((in_array($edit_image_short, $_FILES)) === false){
$value = detail($detail, $field."|".$detail, $field, $page, null, $edit_id);
if($value !=''){
$preview_form .= '<img src="'.$temp_uploads.$value.'" /><input type="hidden" value="'.$value.'" name="'.$field.'|'.$detail.'_move" />';
}
//else show already uploaded image
} else {
if($edit_image !=''){
$preview_form .= '<img src="'.$uploads.$edit_image.'" /><input type="hidden" value="'.$edit_image.'" name="'.$field.'" />';
}
}
$preview_form .= '</td></tr>';
}
} else {
$preview_form .= '<tr><td><strong>'.format($field).':</strong></br>'.stripslashes($value);
if($field == 'date'){
$value = strtotime($value);
}
$preview_form .= '<input type="hidden" value="'.stripslashes($value).'" name="'.$field.'" /></td></tr>';
}
//store incase of editing
$_SESSION[$field] = stripslashes($value);
unset($search);
unset($edit_image);
unset($edit_image_short);
}
$preview_form .= '<tr><td><input type="submit" value="Submit Entry" />';
$preview_form .= '<input type="button" value="Edit" OnClick="window.location.href=\'?p='.$page.'&z=e&i='.$edit_id.'&pv=y\'" /></td></tr>';
$preview_form .= '</table></form></br></div>';
echo $preview_form;
}