从复选框获取 ID
我正在尝试从使用 while 语句打印在页面上的行中的大量复选框中获取 ID。数据库中的每一行旁边都有一个复选框,复选框值中包含 ID。
基本上我想使用 ID 对复选框选定的行进行更新查询。
我使用的复选框的代码是:
<input type="checkbox" name="check_list[]" value="<? echo $rows['id']; ?>">
然后,当提交的代码是:
<?
if(!empty($_POST['check_list'])){
foreach($_POST['check_list'] as $id){
echo "$id was checked! ";
}
}
?>
只是想回显结果以测试它在将其放入查询之前是否有效。问题是……什么也没发生。我只是得到一个空白屏幕。没有错误或任何东西。当然它应该有效,看起来不错,但我不明白为什么它不起作用。
非常感谢任何帮助! :)
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! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用一个 test.php 文件测试了以下代码,
请检查您是否正确获取 $rows['id'] 。否则一切应该工作正常。
谢谢。
Tested below code with one test.php file
please check if you are getting $rows['id'] properly. Things should work fine otherwise.
Thanks.