我有一个 PHP 表单,其中每个项目都有复选框。复选框的名称是唯一的 PHP 变量,因此不会有重复的条目。当用户选中复选框并单击“更新”时。MySQL 数据库应该更新。但它没有。有什么建议吗?谢谢
形式:
<form action='spam.php' method='post'>
<?php
$query = mysql_query("SELECT * FROM files WHERE subject='business' AND active='1' ORDER BY id DESC");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "<h3>Article - Business</h3>
<ol>";
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$title = $row['title'];
$date = $row['date'];
$active = $row['active'];
$desc = $row['description'];
$author = $row['author'];
$email = $row['email'];
$filepath = $row['file'];
$ext = $row['ext'];
$subject = $row['subject'];
echo "<script>
<li>$title <input type='checkbox' name='$id' value='0' /><$ext| <a href='$filepath'>Download</a>|<a id='aTag$id' href=''>Details ↓</a></li>
";
}
if ($numrows == 0)
echo "";
?>
<br />
<input type='submit' value='Update' name='submitbtn'/>
</form><br />
表单动作:
<?php
if (isset($_POST['$id']))
mysql_query("UPDATE files SET active=0 WHERE id=$id AND subject=$subject");
?>