title: Update multiple images separately in a database
body: <p>Please help me! I am stuck from couple of days on a code where I need to update separately images and save the path in a database. When I submit only one image is uploaded and update all the images I have with this one. Here's the code:</p>
  
  <pre><code>&lt;form method="post" action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" enctype="multipart/form-data"&gt;
      &lt;fieldset class="yui"&gt;
  &lt;?php
          include 'php/config.inc.php';
  
        if(isset($_POST['submit'])){
  
           $sql = $mysqli_conn-&gt;query("SELECT * FROM products_code WHERE id='".$_GET['id']."'");
  
             while($row = $sql-&gt;fetch_assoc()) {
             $code = $row["product_code"];
  
            for($i=0;$i&lt;count($_FILES["fileUpload"]["name"]);$i++)  
             {  
             if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")  
             { 
  
                    $imagename = $_FILES["fileUpload"]["name"][$i];
                    $source = $_FILES["fileUpload"]["tmp_name"][$i];
  
  
  
                    $imagepath = $imagename;
                    $save = "images/thmb/" . $imagepath; //This is the new file you saving
                    $orig = "images/" . $imagepath; //This is the original file
                    $result = move_uploaded_file($source, $orig);
                    $file = "images/" . $imagepath; //This is the original file
  
                    list($width, $height) = getimagesize($file);
  
                    if($width &gt; $height){
  
                    $newwidth=600;
                    $newheight=($height/$width)*$newwidth;
  
                    $newwidth1=250;
                    $newheight1=($height/$width)*$newwidth1;
  
                    } else {
  
  
                   $newheight=800;
                   $newwidth=($width/$height)*$newheight;
  
  
                   $newheight1=250;
                   $newwidth1=($width/$height)*$newheight1;
  
                   }
         $tmp=imagecreatetruecolor($newwidth,$newheight);
         $tmp1=imagecreatetruecolor($newwidth1,$newheight1);
         $image = imagecreatefromjpeg($file) ;
         imagecopyresampled($tmp, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ;
         imagejpeg($tmp, $file, 100) ;
         imagecopyresampled($tmp1, $image, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height) ;
         imagejpeg($tmp1, $save, 100) ;
  
          $sql3 = $mysqli_conn-&gt;query("SELECT * FROM photos WHERE product_code = '$code' LIMIT 0,9999");
  
            while($row3 = $sql3-&gt;fetch_assoc()) {
  
              $id = $row3["id"];
              $result = $mysqli_conn-&gt;query("UPDATE photos SET thumb = '$save', full = '$file' WHERE product_code = '$code' AND id = '$id'");
  
             }
                echo "&lt;div class='form'&gt;Mulţumesc! Datele au fost modificate!&lt;br&gt;Veţi fi redirecţionat în (4) secunde&lt;/div&gt;";
  
                echo "&lt;meta http-equiv=Refresh content=4;url=adminprod.php&gt;";
             }
            }
           }
          }
  
    elseif(isset($_GET['id']))
  
          {
          $sql1 = $mysqli_conn-&gt;query("SELECT * FROM products_code WHERE id='".$_GET['id']."'");
  
            while($row1 = $sql1-&gt;fetch_assoc()) {
             $id = $row1["id"];
             $code=$row1["product_code"];
  
          $sql2 = $mysqli_conn-&gt;query("SELECT * FROM photos WHERE product_code = '$code' LIMIT 0,9999");
          $numRows2 = $sql2-&gt;num_rows;
  
             while($row2 = $sql2-&gt;fetch_assoc()) {
               $code = $row2['product_code']; 
               $thumb = $row2['thumb'];
  
          $divcount = 1; 
          if ($divcount == 1)  
            echo '&lt;div&gt;&lt;input type="file" name="fileUpload[]" class="image" value="'.$row2['full'].'" multiple/&gt;&lt;img src="'.$row2['thumb'].'" style="width:auto; height:150px;" border=0/&gt;&lt;/a&gt;&lt;/div&gt;'; // display as you like 
          if ($divcount == $numRows2) {  
            $divcount = 1; 
          } else { 
            $divcount++; 
          }
         }
        }
       }
  ?&gt;
  
      &lt;button name="submit" type="submit" class="button"&gt;Modificați&lt;/button&gt;
      &lt;/fieldset&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Sorry for my english. Thank you!</p>