可能重复:
Error in selecting multiple rows by checkbox error Undefined index: checkbox
我要按复选框选择多行,但复选框值不接受变量$ del_id总是为空。为什么?请求帮助我
<td><input type="hidden" name="id" id="id" value="<?php echo $row["file_serial_id"]; ?>" /><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['file_serial_id']?>" /></td>
if(isset($_POST['send_btn']) and $_POST['send_btn']=="Send"){
$checkbox = isset($_POST['checkbox']) ? $_POST['checkbox'] : 0;
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);
for($i=0;$i<$countCheck;$i++){
$del_id = $checkbox[$i];
$sql2 = "UPDATE retained_file_mst SET mark_to_dispose=1 WHERE file_serial_id='$del_id'";
$result2 = mysql_query($sql2,$conn);
}
// if successful redirect to delete_multiple.php
if($result2){
echo "success";
}else{
echo "error";
}
}
答案 0 :(得分:0)
尝试:
if( (isset($_POST['checkbox'])) && (is_array($_POST['checkbox'])) )
{
while(list($key,$value)=each($_POST['checkbox']))
{
$sql="UPDATE retained_file_mst SET mark_to_dispose=1 WHERE file_serial_id='".mysql_real_escape_string($value)."'";
mysql_query($sql,$conn);
}
}