0

如果选中,我无法将列更新为 yes。我没有收到任何错误。我究竟做错了什么?我尝试了多种方法,包括将数组保留在引号中和引号中。我知道如何通过带有电子邮件地址而不是复选框的表单来做到这一点。我也知道如何使用复选框从数据库中删除行。但是不更新...

  <?php 
      $id = $_GET['id'];
      $select = mysql_query("SELECT * FROM volsMain WHERE ID = '$id'");
      $data = mysql_fetch_array($select);
  ?>

  <?php
      $query="SELECT * FROM volsMain ORDER BY shift_times, position";
      $result = mysql_query($query) or die(mysql_error()); 
      while ($row = mysql_fetch_array($result)){    
  ?>

  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="hidden" name="id" value="<?php echo $id; ?>" />
    <input type="checkbox" name="checkinsat" value="yes"<?php
            if($data['checkinsat'] == 'yes') echo 'checked'; ?>/>
        <input type="submit" >
  </form>

  <?php
   if ($row['saturday'] === 'A.M.') {
       echo '<span class="amShift">';
   } else if ($row['saturday'] === 'P.M.') {
       echo '<span class="pmShift">';
   } else {
    echo '<span>';
   }
    echo "SATURDAY:" . $row['saturday'] . '</span><br />';

   if ($row['sunday'] === 'A.M.') {
    echo '<span class="amShift">';
   } else if ($row['sunday'] === 'P.M.') {
    echo '<span class="pmShift">';
   } else {
    echo '<span>';
   }

   echo "SUNDAY:". $row['sunday'] . '</span><br />';
   echo "<br />SHIRT SIZE:<h2>" . $row['shirt'] . "</h2>";
   echo "<br />VOLUNTEER NAME:<h2>" . $row['agreeName'] . "</h2>";
   echo "<p>Assigned as a volunteer for:<br />" . $row['position'] . "</p>";
   echo "<p>Shift times are scheduled for:<br />" . $row['shift_times'] . "</p>";
   echo "<p>Shifts have been confirmed:<br />" . $row['confirmed'] . "</p>";
   echo "<p>Checked in Friday:<br />" . $row['checkinfri'] . "</p>";
   echo "<p>Checked in Saturday:<br />" . $row['checkinsat'] . "</p>";
   echo "<p>Checked in Sunday:<br />" . $row['checkinsun'] . "</p>";
}
?>

<?php 
   $checkSAT = isset($_POST['checkinsat']) ? "yes" : "no";
   $updateSat = mysql_query("UPDATE volsMain SET checkinsat = '$checkSAT' WHERE ID = '$id'");
   $query = mysql_query($updateSat); 
   $result = mysql_query($query);
   echo "<p>" . print_r($checkSAT) . "</p>";
?>
4

4 回答 4

1
   $checkSAT = isset($_POST['checkinsat']) ? "yes" : "no";
于 2012-06-02T04:10:40.747 回答
0
SET checkinsat = '$checkSAT' ...

PHP 中的变量区分大小写。

于 2012-06-02T04:12:31.373 回答
0

只是通过快速查看它,可能是您的代码:

$updateSat = mysql_query("UPDATE volsMain SET checkinsat = '$checkSAT' WHERE ID = '$id'");

...应该改为:

$updateSat = mysql_query('UPDATE volsMain SET checkinsat = ' . $checkSAT . ' WHERE ID = ' . $id . '');

?

同样应该适用于:

$select = mysql_query("SELECT * FROM volsMain WHERE ID = '$id'");

到:

$select = mysql_query('SELECT * FROM volsMain WHERE ID = ' . $id . '');

不过,这肯定是粗略的:

    $updateSat = mysql_query("UPDATE volsMain SET checkinsat = '$checkSAT' WHERE ID =  '$id'");
$query = mysql_query($updateSat); 
$result = mysql_query($query);

$updateSat 不是纯 SQL 查询,不应在“mysql_query”中调用。如果您希望将其命名为 $result,只需执行以下操作:

        $result = mysql_query("UPDATE volsMain SET checkinsat = '$checkSAT' WHERE ID =  '$id'");
于 2012-06-02T05:04:45.763 回答
0

兄弟 !

  1. 您是否注意到您将表单标签放入 while 循环中?检查这个生成的网页的视图源代码,看看那里显示了多少个 html 表单标签?将 html 表单标签放入循环中是一种错误的方法。您应该在表单元素上使用循环。

  2. 我建议不要在 DB 列中保存是/否,而是保存 1 和 0 值。

于 2012-06-02T08:43:09.057 回答