Need help for this flag variable overwritten

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();.

//member.php

$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);
    
  }
  
   
  
  

}

nope. look at the code highlighting in the else part. there’s something wrong in that line that causes a PHP notice to be emitted.

I updated my post now just wrong typo.

do you get any of the error messages?

Nope, I did not get any error but a success inserting to my database. looks like $upload1 and $upload2 will return it original value.

I think I fixed it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.