Return hidden field with $_POST out of multiple if file is uploaded
<pre><code>&lt;form class="formp" action="" method="post" enctype="multipart/form-data" id="frm" name="wjd"&gt;
&lt;input type="hidden" name="MAX_FILE_SIZE" value="2000000"/&gt;
&lt;p&gt;Gerecht:&lt;/p&gt;&lt;p&gt;Prijs:&lt;/p&gt;&lt;p&gt;Plaatje:&lt;/p&gt;&lt;p&gt;Upload:&lt;/p&gt;
&lt;?php
$resultmenus = mysqli_query($dbc,"SELECT * FROM prijslijst WHERE menunaam='menu\'s'");
while($rowmenus = mysqli_fetch_array($resultmenus,MYSQLI_ASSOC)) {
 echo   "&lt;input type=\"hidden\" name=\"id\" value=\"{$rowmenus['id']}\"/&gt;";
 echo   "&lt;input name=\"gerecht[]\" type=\"text\" size=\"30\" maxlength=\"30\" value=\"{$rowmenus['gerecht']}\"/&gt;";
 echo   "&lt;input name=\"prijs[]\" type=\"text\" size=\"5\" maxlength=\"5\" value=\"{$rowmenus['prijs']}\"/&gt;";
 echo   "&lt;img src=\"../{$rowmenus['plaatje']}\" /&gt;&lt;input  size=\"1\" type=\"file\" name=\"file[]\" id=\"file\"/&gt;";
}
&lt;input type="submit" name="submit" value="verzend" /&gt;
&lt;/form&gt;
</code></pre>

<p>This will output a form with id's 1 to 5 from the db echo'd in the hidden input type field.
My question is: when i upload only 1 file in row 3 with id3 and the rest are empty, is it possible to retrieve only that id?</p>

<p>Because when i try to retrieve it with $_POST['id']; I get the last value which is 5.The is the output to the browser.</p>

<pre><code>&lt;form id="frm" class="formp" name="wjd" enctype="multipart/form-data" method="post" action=""&gt;
&lt;input type="hidden" value="2000000" name="MAX_FILE_SIZE"&gt;
&lt;p&gt;Gerecht:&lt;/p&gt;&lt;p&gt;Prijs:&lt;/p&gt;&lt;p&gt;Plaatje:&lt;/p&gt;&lt;p&gt;Upload:&lt;/p&gt;
&lt;input type="hidden" value="1" name="id"&gt;
&lt;input type="text" value="Menu 1" maxlength="30" size="30" name="gerecht[]"&gt;
&lt;input type="text" value="3.00" maxlength="5" size="5" name="prijs[]"&gt;
&lt;img src="../images/plaatjes/mini_menu3.gif"&gt;
&lt;input id="file" type="file" name="file[]" size="1"&gt;
&lt;input type="hidden" value="2" name="id"&gt;
&lt;input type="text" value="Menu 2" maxlength="30" size="30" name="gerecht[]"&gt;
&lt;input type="text" value="6.00" maxlength="5" size="5" name="prijs[]"&gt;
&lt;img src="../images/plaatjes/mini_menu2.gif"&gt;
&lt;input id="file" type="file" name="file[]" size="1"&gt;
&lt;input type="hidden" value="3" name="id"&gt;
&lt;input type="text" value="Menu 3" maxlength="30" size="30" name="gerecht[]"&gt;
&lt;input type="text" value="6.00" maxlength="5" size="5" name="prijs[]"&gt;
&lt;img src="../images/plaatjes/mini_menu1.gif"&gt;
&lt;input id="file" type="file" name="file[]" size="1"&gt;
&lt;input type="hidden" value="4" name="id"&gt;
&lt;input type="text" value="Menu 4" maxlength="30" size="30" name="gerecht[]"&gt;
&lt;input type="text" value="7.00" maxlength="5" size="5" name="prijs[]"&gt;
&lt;img src="../images/plaatjes/mini_menu3.gif"&gt;
&lt;input id="file" type="file" name="file[]" size="1"&gt;
&lt;input type="hidden" value="5" name="id"&gt;
&lt;input type="text" value="Menu 5" maxlength="30" size="30" name="gerecht[]"&gt;
&lt;input type="text" value="4.00" maxlength="5" size="5" name="prijs[]"&gt;
&lt;img src="../images/plaatjes/mini_menu2.gif"&gt;
&lt;input id="file" type="file" name="file[]" size="1"&gt;
&lt;input type="submit" value="verzend" name="submit"&gt;
&lt;/form&gt;
</code></pre>

<p>This is the handling script.</p>

<pre><code>if(isset($_POST['submit'])) {
        if((array_search('', $_POST["gerecht"])!==false) or (array_search('', $_POST["prijs"])!==false)) { //1 or more field empty
        echo "&lt;span class=\"error\"&gt;Please fill in all fields&lt;/span&gt;";
        exit();
    }else{//field filled in



       foreach ($_FILES['file']['name'] as $i =&gt; $name) {

            if ($_FILES['file']['error'][$i] == 4) { // no upload continue
                continue;
            }
            if ($_FILES['file']['error'][$i] == 0) {

                echo $_POST['id'];


            }//end else error 0

       }//end foreach 
    }//end filled in forms

}else{ //submit button clicked


}
</code></pre>
