Hi All,
I am having trouble in updating a table. The form consists of check boxes that are populated from the first query. I need the form to submit in itself and set the checked fields to 1 and the unchecked to 0. Any and all help will be appreciated.
Thank you in advance
Max
<?php
include("include/session.php");
?>
<form name="menu1" action="" method="POST">
<fieldset>
<br />
<h3>Menu 1</h3>
<?php
$query2="SELECT * FROM menu_1";
$result2 = mysql_query ($query2);
?>
<table border="0" cellspacing="0" cellpadding="5" align="center" >
<tr>
<th></th>
<th>Level9</th>
<th>Level8</th>
<th>Level7</th>
<th>Level6</th>
<th>Level5</th>
<th>Level4</th>
<th>Level3</th>
<th>Level2</th>
<th>Level1</th>
</tr>
<?php
while($row = mysql_fetch_array($result2)) {
$fitem=$row['item'];
$f9=$row['level9'];
if ($f9==1){
$fc9[$fitem]=checked;
}
$f8=$row['level8'];
if ($f8==1){
$fc8[$fitem]=checked;
}
$f7=$row['level7'];
if ($f7==1){
$fc7[$fitem]=checked;
}
$f6=$row['level6'];
if ($f6==1){
$fc6[$fitem]=checked;
}
$f5=$row['level5'];
if ($f5==1){
$fc5[$fitem]=checked;
}
$f4=$row['level4'];
if ($f4==1){
$fc4[$fitem]=checked;
}
$f3=$row['level3'];
if ($f3==1){
$fc3[$fitem]=checked;
}
$f2=$row['level2'];
if ($f2==1){
$fc2[$fitem]=checked;
}
$f1=$row['level1'];
if ($f1==1){
$fc1[$fitem]=checked;
}
?>
<input type="hidden" name="fitem" value="<? echo $fitem; ?>">
<tr align="center">
<td><?php echo $fitem; ?></td>
<td><input type="checkbox" name="checkbox9" value="1" <?php echo $fc9[$fitem]; ?> /><input type="hidden" name="checkbox9" value="0" /></td>
<td><input type="checkbox" name="checkbox8" value="1" <?php echo $fc8[$fitem]; ?> /><input type="hidden" name="checkbox8" value="0" /></td>
<td><input type="checkbox" name="checkbox7" value="1" <?php echo $fc7[$fitem]; ?> /><input type="hidden" name="checkbox7" value="0" /></td>
<td><input type="checkbox" name="checkbox6" value="1" <?php echo $fc6[$fitem]; ?> /><input type="hidden" name="checkbox6" value="0" /></td>
<td><input type="checkbox" name="checkbox5" value="1" <?php echo $fc5[$fitem]; ?> /><input type="hidden" name="checkbox5" value="0" /></td>
<td><input type="checkbox" name="checkbox4" value="1" <?php echo $fc4[$fitem]; ?> /><input type="hidden" name="checkbox4" value="0" /></td>
<td><input type="checkbox" name="checkbox3" value="1" <?php echo $fc3[$fitem]; ?> /><input type="hidden" name="checkbox3" value="0" /></td>
<td><input type="checkbox" name="checkbox2" value="1" <?php echo $fc2[$fitem]; ?> /><input type="hidden" name="checkbox2" value="0" /></td>
<td><input type="checkbox" name="checkbox1" value="1" <?php echo $fc1[$fitem]; ?> /><input type="hidden" name="checkbox1" value="0" /></td>
</tr>
<?php
}
$fpitem=$_POST['fitem'];
$fp9=$_POST['$chekbox9'];
$fp8=$_POST['$chekbox8'];
$fp7=$_POST['$chekbox7'];
$fp6=$_POST['chekbox6'];
$fp5=$_POST['chekbox5'];
$fp4=$_POST['chekbox4'];
$fp3=$_POST['chekbox3'];
$fp2=$_POST['chekbox2'];
$fp1=$_POST['chekbox1'];
$fpq= "UPDATE menu_1 SET level9='$fp9', level8='$fp8', level7='$fp7', level6='$fp6', level5='$fp5', level4='$fp4', level3='$fp3', level2='$fp2', level1='$fp1'";
mysql_query($query);
echo "Record Updated";
echo $fp9;
echo $fp8;
echo $fp7;
echo $fp6;
?>
</table>
<br />
<input name="menu1" VALUE="Apply Changes" type="submit" />
</fieldset>
</form>