<?php
while($row=mysql_fetch_array($result)){
?>
<tr>
<td width="10" scope="col" bgcolor="#E0EEE0"><input type="checkbox" name="shanchu[]" /></td>
<td>.....</td>
 <td>.....</td>
 <td>还有很多数据,省略</td>
 </tr>
 
<?php
include('conn.php');
$delete=$_POST['shanchu'];
foreach($delete as $k=>$v){         
$sql="delete  from record";         //这块应该怎么写?  能不能只判断checkbox选中的情况而 不看其他的数据?
$result=mysql_query($sql,$con);
}
    if($result!=""){
        echo "数据删除成功";
        echo "<br>";
        echo "正在返回删除页面,跳转中...";
        echo "<meta http-equiv='refresh' content='2;url=shanchu.php'>";  
    }
    else {
        echo "数据输入错误";
        echo "<br>";
        echo mysql_error();
    }
?>第一改动:一点改进<td width="10" scope="col" bgcolor="#E0EEE0"><input type="checkbox" name="shanchu[]" value="<?php echo $row['no']?>" /></td>    
<!--这里加入了一个数据库中的值-->
sql语句变成这样$sql="delete  from record where no='$shanchu[$k]'";  
Parse error: syntax error, unexpected $end 
in C:\AppServ\www\deleterecord.php on line 29
第二次改动
把下面的删除的php单独到一个文件中,进行处理
无错误提示    提示数据删除成功             但实际上无效果         求解 这是什么原因?

解决方案 »

  1.   

    删除记录需要有唯一的标识,不然就可能误删
    一般表中都有主键 id,这就是唯一的标识
    于是表单里
    ...<input type="checkbox" name="shanchu[]" value=<?php echo $row['id'] ?>/>...这样就和表中的记录对应起来了删除时
    $sql = 'delete  from record where id  in (' . join(',', $_POST['shanchu']) . ')';
      

  2.   

    现在改成
    <td width="10" scope="col" bgcolor="#E0EEE0"><input type="checkbox" name="shanchu[]" value="<?php echo $row['no']?>" /></td>  
    <!--no是主键,唯一值-->
    if(!empty($_POST['shanchu'])){
    $str = explode(",",$_POST['shanchu']);
    $sql = 'delete from record where in (' . join(',', $_POST['shanchu']) . ')';
            $result=mysql_query($sql,$con);
    }
    数据输入错误You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'in (71,70)' at line 1这个sql的in附近是哪里错了?
      

  3.   

    如何进行checkbox的选中判断print_r($_POST);
      

  4.   

    $sql = 'delete from record where no in (' . join(',', $_POST['shanchu']) . ')';