怎么进行checkbox的选中判断

WBOY
Release: 2016-06-13 10:43:03
Original
681 people have browsed it

如何进行checkbox的选中判断

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpwhile ($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> <?phpinclude ('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();    }?>
Copy after login


第一改动:一点改进  

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单独到一个文件中,进行处理
无错误提示 提示数据删除成功 但实际上无效果 求解 这是什么原因?

------解决方案--------------------
删除记录需要有唯一的标识,不然就可能误删
一般表中都有主键 id,这就是唯一的标识
于是表单里
.../>...

这样就和表中的记录对应起来了

删除时
$sql = 'delete from record where id in (' . join(',', $_POST['shanchu']) . ')';
------解决方案--------------------
如何进行checkbox的选中判断

print_r($_POST);


------解决方案--------------------
echo $sql;
------解决方案--------------------
探讨

引用:

删除记录需要有唯一的标识,不然就可能误删
一般表中都有主键 id,这就是唯一的标识
于是表单里
.../>...

这样就和表中的记录对应起来了

删除时
$sql = 'delete from record……
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!