从复选框中获取ID
I'm trying to get the ID's from a load of checkboxes that are in rows that are printed out on a page using a while statement. Each row from the database has a checkbox next to it with the ID in the checkbox value.
Basically I want to do a update query on the checkbox-selected rows, using the ID.
The code for the checkboxes that I have used is:
<input type="checkbox" name="check_list[]" value="<? echo $rows['id']; ?>">
Then when the code for the submit is:
<?
if(!empty($_POST['check_list'])){
foreach($_POST['check_list'] as $id){
echo "$id was checked! ";
}
}
?>
Just wanted to echo out the results to test that it works before putting it into a query. Trouble is...nothing happens. I just get a blank screen. No error or anything. Surely it should work, it looks right but I don't understand why it doesnt work.
Any help is most appreciated! :)
我正在尝试从一系列复选框中获取ID,这些复选框在页面上打印出来 使用while语句。 数据库中的每一行都有一个复选框旁边的复选框值ID。 p>
基本上我想使用ID对复选框选择的行进行更新查询。 p>
我使用的复选框的代码是: p>
&lt; input type =“checkbox”name =“check_list [] “value =”&lt;?echo $ rows ['id'];?&gt;“&gt;
code> pre>
然后当提交的代码为: p>
&lt;?
if(!empty($ _ POST ['check_list'])){
foreach($ _ POST ['check_list'] as $ id){
echo “$ id已经过检查了!”;
}
}
?&gt;
code> pre>
只是想要回应结果以测试它在放入之前是否有效 它进入一个查询。 麻烦是......没有任何反应。 我只是得到一个空白的屏幕。 没有错误或任何事情。 当然它应该工作,它看起来正确,但我不明白为什么它不起作用。 p>
非常感谢任何帮助! :) p>
div>
Tested below code with one test.php file
<?php
if(!empty($_POST['check_list']))
{
foreach($_POST['check_list'] as $id){
echo "<br>$id was checked! ";
}
}
?>
<form method="post" name="frm">
<input type="checkbox" name="check_list[]" value="1"> 1
<input type="checkbox" name="check_list[]" value="2"> 2
<input type="checkbox" name="check_list[]" value="3"> 3
<input type="checkbox" name="check_list[]" value="4"> 4
<input type="submit" name="submit" />
</form>
please check if you are getting $rows['id'] properly. Things should work fine otherwise.
Thanks.