Php 获取复选框列表并在mysql中获取它们
我从复选框列表中获取值,并希望在mysql中获取这些值,就像下面的sql查询所示:Php 获取复选框列表并在mysql中获取它们,php,mysql,checkbox,Php,Mysql,Checkbox,我从复选框列表中获取值,并希望在mysql中获取这些值,就像下面的sql查询所示: <form action="index2.php" method="get"> <input type="checkbox" name="check_list[]" alt="Checkbox" value="one">One <input type="checkbox" name="check_list[]" alt="Checkbox" value="two"&
<form action="index2.php" method="get">
<input type="checkbox" name="check_list[]" alt="Checkbox" value="one">One
<input type="checkbox" name="check_list[]" alt="Checkbox" value="two">Two
<input type="checkbox" name="check_list[]" alt="Checkbox" value="three">Three
<input type="submit" value="Submit">
<?php
if(!empty($_GET['check_list']))
{
foreach($_GET['check_list'] as $check)
{
$ids = implode(',', $check);
echo $ids;
}
}
$sql="SELECT * FROM table WHERE activity IN($ids)";
I've tried with array(), implode(), explode()...
Nothing works.
this is a simplified code: I did not put the code against injection.
Can anybody be of help. Thanks :)
?>
一
二
三
问题是什么?$ids
是否为空?它是否包含错误的值?代码运行了吗?警告:内爆():使用$\u GET:values ok->ex:onetwotree(全部附加)传递的参数无效。您从var\u dump($\u GET['check\u list'])
中得到了什么?然后您只需要内爆(',',$\u GET['check\u list'])
获得一个逗号分隔的列表,您可以在中传递到。记住验证你的数据(你说你已经这样做了,这很好!);您需要逻辑来处理$\u GET['check\u list']
为空的情况。