【发布时间】:2020-05-02 17:41:51
【问题描述】:
我是 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++; }
?>
<select name="selected_mem_type" >
<?php
$sql = "select Name from membership_type";
$result = mysqli_query($conn,$sql);
$i = 0;
while($DB_ROW = mysqli_fetch_array($result)){
?>
<option>
<?php echo $DB_ROW['Name']; ?>
</option>
<?php
$i++;} ?>
</select>
<input type ="text" name="user_card_no" placeholder="Credit Card No">
<input type="date" name="user_card_expire_date" placeholder="Expire Date of Card">
<button type="submit" class="signupbtn" name="signup-submit"> Signup </button>
<button type="submit" class="signupbtn" name="home-submit"> Home </button>
</div>
</form>
问题是当我打算使用$_POST['check_list']via foreach 循环获取选定的复选框时,它会根据选定复选框的数量打印 "on"。如果用户在 $_POST['check_list'] 中选择 3 个复选框,则有 3 个元素是 "on" 。当我选择两件事时,让我们说,并用print_r 打印$_POST['check_list'] 它输出Array ( [0] => on [1] => on [2] => on )
我搜索了很多,但无法找到解决方案。感谢您的帮助,感谢您的关注。
【问题讨论】:
-
经过 10 年的内容生成和数百万个问题,大多数基本编程问题至少有 5 页来表达如何解决给定问题。在提出新问题之前,请在寻找解决方案时多花点功夫。