从复选框接受数据,php进行数据操作

来源:互联网 发布:linux解压zip命令行 编辑:程序博客网 时间:2024/05/29 10:15
<pre name="code" class="html"><input type="checkbox"  onclick="SetCheckBoxState(this)" name="t[]" value="<?php echo $row['id'];?>" ><?php echo $row['num'];?>票</p></div>


input 表单中name使用t[],数组的形式实现,然后在接受post提交页面

$arr=$_POST['t'];
然后循环数组插入数据库,value是id值,所以数组中存的是每个id的值,所以循环操作,是每个id对应的票数加1
//我循环$arr数组,在使用$arr数组循环出来的变量,投票加一for($i=0;$i<count($arr);$i++){$sql="update info set num=num+1 where id= ".$arr["$i"];$rs=mysqli_query($link,$sql);if(!$rs){return false;}//echo $sql;//echo $arr["$i"];}


0 0