-1

可能重复:
通过复选框错误选择多行时出错未定义索引:复选框

我要通过复选框选择多行,但复选框值不带变量 $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";
    }
}
4

1 回答 1

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);
    }
}
于 2012-06-29T11:41:55.897 回答