我有一个表格,在表格中为每个工程师显示一个复选框。当提交表单时,如果工程师的复选框没有被勾选,他们就会从工作中移除($diary_id)。
目前的代码可以正常工作,但页面会在返回下一页之前简要显示此错误。
in_array() 期望参数 2 是数组,给定错误为 null
表格上的代码...
$sql = "SELECT * FROM users WHERE type = 'engineer' ORDER BY first_name";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result)){ ?>
<div style="width:70px; float:left">
<input type="hidden" name="engineer_on_page[]" value="<? echo $row['id']; ?>"/>
<input type="checkbox" name="engineer[]" <?
$eng_id= $row['id'];
$result2 = mysql_query("SELECT * FROM calls_engineers WHERE call_ce = '$diary_id' AND engineer_ce = '$eng_id'");
if((mysql_num_rows($result2)) > 0)
{ echo 'checked="checked"';
?> value="<? echo $row['id']; ?>" />
<? echo ' '.$row['first_name']; }
else {
echo "value=".$row['id']." />";
echo ' '.$row['first_name'];
}
?>
</div>
<? } ?>
mysql 去掉未选中的工程师
foreach($_POST['engineer_on_page'] as $engineer_id) {
$sql = "SELECT * FROM calls_engineers WHERE call_ce = '$diary_id' AND engineer_ce = '$engineer_id'";
$result = mysql_query($sql)or die(mysql_error());
if(!in_array($engineer_id, $_POST['engineer'])){
if(mysql_num_rows($result) > 0){
$sql = "DELETE FROM calls_engineers WHERE engineer_ce = '$engineer_id' AND call_ce = '$diary_id'";
$result = mysql_query($sql)or die(mysql_error());
}
}
}
我试图在停止错误的 foreach 循环之前将 $_POST['engineer'] 初始化为数组 ($_POST['engineer'] = array();) ,但它也会停止页面工作,没有错误消息,它不再起作用了。
我知道该页面需要更新为 mysqli,但我想在此之前解决此问题。
谢谢