Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php从复选框检索数据_Php - Fatal编程技术网

使用php从复选框检索数据

使用php从复选框检索数据,php,Php,我已经从复选框中动态发送了值,当我尝试使用循环动态检索所有值时,它只是在加载时继续。 用于从复选框发送值的我的代码: while ($row=mysql_fetch_array($query)) { $member_id=$row["member_id"]; <input type='checkbox' name='check' value='$member_id'> } // this is working. but when i try to fetch the

我已经从复选框中动态发送了值,当我尝试使用循环动态检索所有值时,它只是在加载时继续。 用于从复选框发送值的我的代码:

while ($row=mysql_fetch_array($query))
{

   $member_id=$row["member_id"];
   <input type='checkbox' name='check' value='$member_id'>
}

// this is working. but when i try to fetch the data from checkbox from only where the tick is given it doesn't work. this is how i tried to fetch the data


while(isset($_POST['check']))
{
   echo $_POST['check']."<br>";

}
while($row=mysql\u fetch\u array($query))
{
$member_id=$row[“member_id”];
}
//这是有效的。但是,当我试图从复选框中获取数据时,仅从给出勾号的位置获取数据是不起作用的。这就是我试图获取数据的方式
while(设置($_POST['check']))
{
echo$_POST['check']。“
”; }
并将html标记更改为:

<input type="checkbox" name="check[]" value=".$member_id.">

您添加了While循环,条件始终为true。所以循环将变得无限。 将循环更改为foreach,如下所示

foreach ($_POST['check'] as $value)
{
  echo $value."<br>";
}
while ($row=mysql_fetch_array($query))
{

  $member_id=$row["member_id"];
  echo "<input type='checkbox' name='check' value='$member_id'>";
}

如果你想得到所有的复选框

错误将导致无限循环

while(isset($_POST['check']))
{
    echo $_POST['check']."<br>";
}
while(设置($\u POST['check']))
{
echo$_POST['check']。“
”; }
许多正确的备选方案之一:

foreach ($_POST['check'] as $val) {
     echo $val.'<br>';
}
foreach($\u POST['check']作为$val){
回显$val.“
”; }
这里的诀窍是,当您有多个同名复选框,并且希望在服务器端获取所有选中值时,需要在html中复选框字段的名称后添加[],例如

<input type='checkbox' name='check[]' value='$member_id'>
表示无限循环。应该是

if(isset($_POST['check']))
foreach($_POST['check'] as $each_check)
 echo $each_check;

最后,它是一个复制品。请在再次提问之前搜索:)

编辑完您的问题后,我非常担心。这就是php文件中的内容。我说的是while循环代码。“当设置了
$\u POST['check']
时,输出它,然后重复”。。。这怎么不是一个明显的无限循环?你的意思是
if
而不是
while
?dup:使用if循环只取一个chekbox值,但我需要多个。我现在能做什么?
while(isset($_POST['check']))
if(isset($_POST['check']))
foreach($_POST['check'] as $each_check)
 echo $each_check;