我是PHP和Mysql的新手。我在Mysql中有一个名为“has”的表,我存储了客户的物理对齐方式。有两个属性 CustomerID 和 PyhsicalAilmentName 。在注册屏幕中,我希望用户在复选框中选择它们。我能够使用此表单代码将物理对齐从数据库提取到复选框中。
<form action="includes/signup.inc.php" style="border:1px solid #ccc;width: 50%;margin: 0 auto" method="post" >
<div class="container" >
<h1>Sign up</h1>
<p>Please fill in this form to create an account.(Your username should start with "C_")</p>
<hr>
<input type="text" name="username" placeholder="Name">
<input type="text" name="user_last_name" placeholder="Last Name">
<input type="text" name="uid" placeholder="Username">
<input type="password" name="pwd" placeholder="Password">
<input type="password" name="pwd-repeat" placeholder="Repeat Password">
<input type="text" name="user_weight" placeholder="Weight(in terms of kilogram)">
<input type="text" name="user_length" placeholder="Length(in terms of cm)">
<input type="text" name="user_age" placeholder="Age">
<p> Phsical Alignments</p>
<?php
$sql = "select Name from physical_ailment";
$result = mysqli_query($conn,$sql);
$i = 0;
while($db_row = mysqli_fetch_array($result)){
?>
<input type="checkbox" name="check_list[]"> <?php
echo $db_row["Name"]; ?> <br>
<?php
$i++; }
?>
问题是,当我打算通过foreach循环获取选定的那些时,它会根据所选复选框的数量打印“on”。如果用户选中 3 个复选框,则有 3 个元素为“on”。当我选择2件事时,让我们说,并打印输出,我搜索了很多,但无法找到解决方案。感谢任何帮助,感谢您的关注。$_POST['check_list']$_POST['check_list']$_POST['check_list']print_rArray ( [0] => on [1] => on [2] => on )
明月笑刀无情