I have problem on my flag variable it will remember the value when it is first assigned. even it is change when it falls to my else statement. but in the end in it will return back to it’s original value. and it will execute my function saveData();.
$upload1 = 1;
$upload2 = 1;
if(isset($_POST['submit']){
//checking for the upload1 file
if (preg_match('/\^image/p?jpeg$/i', $_FILES['upload1']['type']) ||
preg_match('/\^image/gif$/i', $_FILES['upload1']['type']) ||
preg_match('/\^image/(x-)?png$/i', $_FILES['upload1']['type'])){
if (move_uploaded_file($_FILES['upload1']['tmp_name'], $uploadfile1)) {
$upload1 = 1;
}else{
$upload1 = 0;
$error = 'Error in uploading file.';
}
}
else{
$upload1 = 0;
$error = 'Please submit a JPEG, GIF, or PNG image file.';
}
//checking for the upload2 file
if($upload1 == 1){
if (preg_match('/\^image/p?jpeg$/i', $_FILES['upload2']['type']) ||
preg_match('/\^image/gif$/i', $_FILES['upload2']['type']) ||
preg_match('/\^image/(x-)?png$/i', $_FILES['upload2']['type'])){
if (move_uploaded_file($_FILES['upload2']['tmp_name'], $uploadfile2)) {
$upload2 = 1;
}else{
$upload2 = 0;
$error = 'Error in uploading file.';
}
}
else{
$upload2 = 0;
$error = 'Please submit a JPEG, GIF, or PNG image file.';
}
}
if($upload1 == 1 && $upload2 ==1){ //here it will always executed to true
//perform saving to database here.
// saveData($param1,$param2,$parm3);
}
}