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条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题