Php 如何将while循环生成的复选框中的值存储到数据库中?
如何存储循环生成的多个复选框的值。 我已经看到了很多从复选框中获取值的方法,但是如果它是这样生成的呢Php 如何将while循环生成的复选框中的值存储到数据库中?,php,Php,如何存储循环生成的多个复选框的值。 我已经看到了很多从复选框中获取值的方法,但是如果它是这样生成的呢 if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { echo'<div class="checkbox "> <label> <input type="checkbox" id="chkb
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_assoc($result))
{
echo'<div class="checkbox ">
<label>
<input type="checkbox" id="chkbox" name="requirement_name[]" value="'.$row['requirement_id'].'">
'.$row['requirement_name'].'
</label>
</div>';
}
}
if(mysql\u num\u行($result)>0)
{
while($row=mysql\u fetch\u assoc($result))
{
回声'
“.$row['requirement_name']”
';
}
}
我可以使用此代码,但它只显示检查了多少以及检查了什么:
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['requirement_name'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['requirement_name']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
foreach($_POST['requirement_name'] as $selected) {
echo "<p>".$selected ."</p>";
}
}
else{
echo "<b>Please Select Atleast One Option.</b>";
}
}
?>
您想做什么?存储它?将其存储在哪里?我想将该值存储到另一个表@abracadver中。然而,如果它是这样生成的,我不知道怎么做。可能是@Johan的复制品我已经研究过了,但那一个太深了。那篇文章中答案的实质是;使用默认复选框值为零的隐藏字段。否则,该字段不会与表单一起发布。