我在 html 输入表单中有一个复选框字段。在此值是从另一个表中获取的。我想借助此复选框选择多个用户。我的代码有什么问题
<div class="form-group col-md-6">
<label> Supervised BY( At IUAC)<span style="color:red;">*</span></label>
<input type="checkbox" name="user" > <br>
<checkbox value=""> </checkbox>
<?php
$sql = "SELECT * from tblstaff ";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<option value="<?php echo htmlentities($result->id);?>"><?php echo htmlentities($result->name);?></option>
<?php }} ?>
我试过这段代码,但它没有显示复选框
最佳答案
使用输入类型Checkbox
字段这样
<?php
foreach($results as $result)
{ ?>
<input type="checkbox" name="<?php echo $result->name; ?>" value="<?php echo $result->name; ?>"> <?php echo $result->name; ?> </br>
<?php } ?>
关于javascript - 带有多值复选框的 HTML 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58534185/