I have a form that extracts data from a mysql database and if a checkbox called update is checked it updates the database. The problem is that if the update field is a checkbox the script updates the first record set regardless of whether the checkbox is checked or not and does not update the last record. If I use a select menu instead of a checkbox it works fine. Heres the relevant bits of the code: <input name="update[]" type="checkbox" id="update" value="1"> for($i=0;$i<$count;$i++){ if($update[$i] ==1){ // do stuff ###DOES NOT WORK ********************************************* <select name="update[]" id="update"> <option value="0" selected>No</option> <option value="1">Yes</option> </select> for($i=0;$i<$count;$i++){ if($update[$i] ==1){ // do stuff ###WORKS FINE Any ideas? Thanks
is this a checkbox or a dropdown? js or ajax? use onchange event or onSelect on every checkbox that has the same name, remeber to put a parameter onchange="yourFunction(this.value)" then catch it with $_REQUEST['checkboxname']; then do your query here
The form is output by php as a standard html form. When the update field is a checkbox it does not work but when it's a select it works fine. PHP seems to be handling checkbox arrays differently than the text field arrays or the select box arrays.