先介绍一下我的代码:
<?php include ('header.php'); ?>
<h3>Extra menu items , van eigen pagina's</h3>
<!-- zet menu onderdelen aan of uit -->
<?php
if ($_POST['submit'] == 'Verzenden') {
$checkbox_vals = $_POST['np_menu_active_post']; // This will pass the selected checkbox values as an array
//if(count($checkbox_vals) > 0) {
// Loop it and update the values in DB
foreach( $checkbox_vals as $key ){
$updatequery = "UPDATE custompage set np_menu_active = '$key'";
mysql_query($updatequery) or die("Couldn't get file list");
}
//}
?>
<meta HTTP-EQUIV="Refresh" CONTENT="0"; URL="<?php echo $_SERVER['PHP_SELF'];?>">
<?php
}
?>
<?php
$dbQuery_custom_toggle = "SELECT * ";
$dbQuery_custom_toggle .= "FROM custompage";
$result_custom_toggle = mysql_query($dbQuery_custom_toggle) or die("Couldn't get file list");
while($row = mysql_fetch_array($result_custom_toggle)) {
// $nptitel = $row['np_titel'];
// $nptekst = $row['np_tekst'];
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="np_menu_active_post[]" value="0" />
<?php echo $row['np_menu_titel'];?> <input type="checkbox" name="np_menu_active_post[]" value="1" <?php if($row['np_menu_active'] == "1"){echo 'checked="checked"';}?> /> <br />
<?php
}
?>
<input type="Submit" name="submit" value="Verzenden" class="btn-primary">
</form>
<!-- einde menu toggles -->
<br />
<br />
所以我试图让这个表单根据复选框将 1 值或 0 值写入 mysql db。
它部分工作,当我选择最后一个复选框时,它会检查所有内容,并将其写入数据库。