-1

我有一张没有用户的桌子

$listuser = mysql_query('SELECT id,firstname,lastname,approve FROM user');
echo '<form action="" method="post">';
echo '<table>
          <tr><td>Name</td>
              <td>AdminApprove</td>
          </tr>';
while($row = mysql_fetch_assoc($listuser))
{
  $id = $row['id'];
  $firstname = $row['firstname'];
  $lastname  = $row['lastname'];
  echo '<tr>
           <td><input type="hidden" name="id[]" value ='.$id.'></td>
           <td>'.$firstname.''.$lastname.'</td>
            <td><input type="checkbox" name="approve[]"></td>
        </tr>';
}
echo '<tr><td><input type="submit" name="submit" value="submit"></td></tr>';
echo '</table></form>';

提交表格后

   $postedid = $_POST['id'];
   $approve = isset($_POST['approve']) ? 1 : 0;   
   $approvestudent = 'UPDATE user SET approve = '.$approve.' WHERE id = '.$postedid.'';
   $result_update = mysql_query($approvestudent);  

我想为每个学生一次批准一个或多个,并且批准的复选框值需要使用 0 或 1 存储到数据库中

4

1 回答 1

0

$_POST['id']是数组不是字符串或整数

您可以使用phpserialize()函数将数组转换为字符串

 $postedid = $_POST['id'];
   $approve  = $_POST['approve'];

应该

 $postedid = serialize($_POST['id']);
   $approve  = serialize($_POST['approve']);
于 2012-10-18T17:27:53.277 回答