我一直在尝试更新包含复选框的表单,这比我预期的要难一些。
现在我认为我做的一切都是正确的,它只是没有更新。我现在不知道为什么。
这是带有表单的页面:
<?php
include "style.css";
include "connect.php";
include "header.php";
//This code runs if the form has been submitted
$id = htmlspecialchars($_GET["id"]);
$query = "SELECT * FROM draaiboek_users WHERE id = '$id'";
$result = mysql_query($query);
$data=mysql_fetch_array($result);
?>
<table>
<p align="right"><button onclick="history.go(-1);">Terug</button></p>
</table>
<form action="users-update.php" method="post">
<input type="hidden" name=ud_id" value="<? echo $id; ?>">
<table border="0">
<br>
<tr><td>Gebruikersnaam:</td><td>
<input type="text" name="ud_username" maxlength="60" value="<? echo ($data['username']); ?>">
</td></tr>
<tr><td>Module Basisgegevens:</td><td>
<input type="checkbox" name="ud_mod_basisgegevens" value="1"<?php if($data['mod_basisgegevens'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Personeel:</td><td>
<input type="checkbox" name="ud_mod_personeel" value="1"<?php if($data['mod_personeel'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Vrijwilligers:</td><td>
<input type="checkbox" name="ud_mod_vrijwilligers" value="1"<?php if($data['mod_vrijwilligers'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Gasten:</td><td>
<input type="checkbox" name="ud_mod_gasten" value="1"<?php if($data['mod_gasten'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Artistiek:</td><td>
<input type="checkbox" name="ud_mod_artistiek" value="1"<?php if($data['mod_artistiek'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Publiekswerking:</td><td>
<input type="checkbox" name="ud_mod_publiekswerking" value="1"<?php if($data['mod_publiekswerking'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Techniek:</td><td>
<input type="checkbox" name="ud_mod_techniek" value="1"<?php if($data['mod_techniek'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><td>Module Financien:</td><td>
<input type="checkbox" name="ud_mod_financien" value="1"<?php if($data['mod_financien'] == '1') echo 'checked'; ?>>
</td></tr>
<tr><th colspan=2><br><input type="submit" name="submit"
value="Update"></th></tr> </table>
</form>
这是更新页面:
<html>
<head>
<?php
include 'style.css';
include 'connect.php';
include 'security.php';
include 'header.php';
?>
</head>
<body>
<table>
<?php
$ud_id = $_POST['ud_id'];
$ud_username = $_POST['ud_username'];
$ud_mod_basisgegevens = ($_POST['ud_mod_basisgegevens'] == '1') ? "1" : "0";
$ud_mod_personeel = ($_POST['ud_mod_personeel'] == '1') ? "1" : "0";
$ud_mod_vrijwilligers = ($_POST['ud_mod_vrijwilligers'] == '1') ? "1" : "0";
$ud_mod_gasten = ($_POST['ud_mod_gasten'] == '1') ? "1" : "0";
$ud_mod_artistiek = ($_POST['ud_mod_artistiek'] == '1') ? "1" : "0";
$ud_mod_publiekswerking = ($_POST['ud_mod_publiekswerking'] == '1') ? "1" : "0";
$ud_mod_techniek = ($_POST['ud_mod_techniek'] == '1') ? "1" : "0";
$ud_mod_financien = ($_POST['ud_mod_financien'] == '1') ? "1" : "0";
$query = "UPDATE draaiboek_users SET username = '$ud_username' mod_basisgegevens = '$ud_mod_basisgegevens' mod_personeel = '$ud_mod_personeel' mod_vrijwilligers = '$ud_mod_vrijwilligers' mod_gasten = '$ud_mod_gasten' mod_artistiek = '$ud_mod_artistiek' mod_publiekswerking = '$ud_mod_publiekswerking' mod_techniek = '$ud_mod_techniek' mod_financien = '$ud_mod_financien' WHERE id = '$ud_id'";
mysql_query($query);
echo "Record updated";
mysql_close();
?>
</table>
</body>
</html>
任何想法这是怎么来的?
谢谢,
大安