我想按复选框删除我的数据,我这段代码有什么错? 代码实在难看其中一处错误$str="delete from list where id='$_POST[id]' "; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $id=$arr["$index"]["id"];我在这里已经把数据库里id的值赋给$id了,我习惯这样用,因为我用不惯那些双、单引号 <form action="del_2.php" method="post">这里应该改为action="",我是想用复选框选中后然后实现删除。应该怎么做呀?有哪个高手指点一下 <?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> </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> 1\你应该用一个form,但是现在用了两个form,不可能同时取道name和id. 需要把两个form里的东西都写到一个form里.2\$str="delete from list where id='$id' "; 也不对,$id应该是$_POST[checkbox].但是这种sql只是支持checkbox选择一条的删除,多条的时候不起作用.faq里面有类似的checkbox的表单的操作的可以解决你的问题.另外楼上的代码也不全对,但是实现的多条选取的方法是对的. 请高手帮我指出这段代码中的错误 谁可以帮我检查一下这段程序? 求个正则匹配问题。 求助php达人为网站添加功能 php 判断执行超时 清單的值怎傳去文字欄位 php如何实现虚拟主机 php 数组合并 【有没有用内存虚拟磁盘做web document root的?】 关于php的mysql注入漏洞,有兴趣的进来看一下~~~ 写一个PHP的大型项目,需要哪些程序以外的东西? 在线人数统计
我在这里已经把数据库里id的值赋给$id了,我习惯这样用,因为我用不惯那些双、单引号
这里应该改为action="",我是想用复选框选中后然后实现删除。
应该怎么做呀?有哪个高手指点一下
<?
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> </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>