代码实在难看其中一处错误$str="delete from list where id='$_POST[id]' ";

解决方案 »

  1.   

    $id=$arr["$index"]["id"];
    我在这里已经把数据库里id的值赋给$id了,我习惯这样用,因为我用不惯那些双、单引号
      

  2.   

    <form action="del_2.php" method="post">
    这里应该改为action="",我是想用复选框选中后然后实现删除。
    应该怎么做呀?有哪个高手指点一下
      

  3.   


    <?
    mysql_connect("localhost","root","");
    mysql_select_db("contact");
    $name=$_POST["name"];
    // 删除文本框输入的名字对应的记录
    if($name)
    {
        $str="delete from list where id='$id' ";
        echo $str;
        mysql_query($str);
    }
    // 循环删除选中复选框对应的记录
    for($i = 0; $i < count($checkbox); $i++)
    {
        $sqlstr = "delete from list where id = $checkbox[$i]";
        mysql_query($sqlstr);
    }
    ?>
    <?echo $_POST[checkbox];?>
    <form action="<?php echo $PHP_SELF; ?>" method="post">
    name<input type="text" name="name">
    <input type="submit" value="del">
    </form>
    <a href="phonebook.php">back</a>
    <?
    $result=mysql_query("select * from list");
    $sn_index=mysql_num_rows($result);
    for($index=0;$index<$sn_index;$index++)
    $arr[$index]=mysql_fetch_array($result);
    ?>
    <table width="300" border="0">
    <form action="<?php echo $PHP_SELF; ?>" method="post">
      <tr> 
        <td>id</td>
        <td>name</td>
        <td>sn</td>
        <td>&nbsp;</td>
      </tr>  <?
    for($index=0;$index<$sn_index;$index++){
    ?>
    <tr>
    <td><? echo $arr["$index"]["id"]?></td>
        <td><? echo $arr["$index"]["name"]?></td>
        <td><? echo $arr["$index"]["pn"]?> </td>
        <td><? $id=$arr["$index"]["id"];
    echo $id;
    echo "<input type=checkbox value='$id' name=checkbox[$index]>";?> </td>
      </tr>
    <?
     }
    ?>
    </table>
    <input type="submit" value="del">
    </form>
      

  4.   

    1\你应该用一个form,但是现在用了两个form,不可能同时取道name和id. 需要把两个form里的东西都写到一个form里.2\$str="delete from list where id='$id' "; 也不对,$id应该是$_POST[checkbox].但是这种sql只是支持checkbox选择一条的删除,多条的时候不起作用.faq里面有类似的checkbox的表单的操作的可以解决你的问题.另外楼上的代码也不全对,但是实现的多条选取的方法是对的.