doufutao4428 2017-10-06 06:17
浏览 44
已采纳

复选框的二进制值不存储到数组中

This post is regarding my previous question continuation Bind values to checkbox

These Below code i have used in one of my php page

$Qualification=$_SESSION['Qualification']; // gives value = 1,2,3,
        $selectedqualification= explode(",", $Qualification);
        $selectedqualification= array_filter($selected);

Now these values are used to bind into checkbox-

<?php  $query = "SELECT * FROM Qualification";

  $result = mysqli_query($dbcon,$query);
  while($row=mysqli_fetch_array($result)){ 
?>  
<input type='checkbox' value='"<?php $row['Id'] ?> "' name='Qualification[]'  <?php if (in_array($row['Id'], $selectedqualification)){ echo "checked"; } ?> /><?php echo $row['Description'] ?><br>

<?php } ?>

The Output of these will be displayed as

[/]Teacher
[/]ENgineer
[/]Doctor
[]Banker

Where the three values are checked .

Now on submit of the button using method post in the form

if(isset($_POST['submit']))
{

   $AllQualification="";

print_r($_POST['Qualification']);

        foreach($_POST['Qualification'] as $Qualification) 
        {
           $AllQualification .=$Qualification.",";
        }
echo $AllQualification

}

The output will be

Array ( [0] => " " [1] => " " [2] => " " [3] => " ")
'" "," "," "

Values are not getting passed to the array. How to get the values to bind to array? Any help appreciated.

  • 写回答

3条回答 默认 最新

  • dqqs64238 2017-10-06 06:24
    关注

    You have to change check-box html like below:-

    <input type='checkbox' value="<?php echo $row['Id']; ?>" name='Qualification[]'  <?php if (in_array($row['Id'], $selectedqualification)){ echo "checked"; } ?> /><?php echo $row['Description'] ?><br>
    

    CHANGE I MADE (added echo and removed single quotes):-

    value="<?php echo $row['Id']; ?>"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 MIT控制器能控制不稳定系统吗
  • ¥15 公司代码X对业务伙伴X无效,处理方法?
  • ¥15 微信内链接跳转到浏览器打开怎么实现
  • ¥15 三角波可以直接加施密特电路整形到矩形波吗实物
  • ¥15 html,php,在使用html请求php文件时发生了错误,无法请求到php文件读取数据库并用javascript进行数据显示,刷新
  • ¥15 touchsocket udp组播
  • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
  • ¥15 VS2012中查询语句无法填入解析,数值传不进去
  • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
  • ¥15 怎么让ai定时给我发信息 c#或者python