0

我有一个 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  &darr;</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");

?>
4

1 回答 1

1

Firstly I suggest that You seperate retrieving data from database and echoing input fields. Secondly, I suppose that

<?php while($row = mysql_fetch_array($result)): ?>
    <input type="checkbox" name="<?=$row['id']?>
<?php endwhile; ?>

looks prettier.

Third thing, You didn't want to try:

if (isset($_POST[$id])) ...

not

if (isset($_POST['$id'])) ...

And the last thing, is that we need to know errors or what is wrong.

于 2012-07-06T06:19:23.457 回答