这是我的表单,类别来自while循环的数据库。 我想将选中的输入只插入到数据库中。我如何发布复选框与PHP?
如何检测选中哪个复选框?
<form action="account.php" method="POST">
<ul class="account-info">
<li>Category1 : <input type="checkbox" value="val1" name="cat1"></li>
<li>Category2 : <input type="checkbox" value="val2" name="cat1"></li>
<li>Category3 : <input type="checkbox" value="val3" name="cat1"></li>
<!-- while continues -->
<li>Category100 : <input type="checkbox" value="val100" name="cat1"></li>
</ul>
<input type="submit" value="submit" />
</form>
只有选择复选框在传递POST数组。 –
你可能会想到一个单选按钮。 (因为你问哪一个被选中,并将它们全部命名为cat1)。你的代码中有复选框,每一个都需要一个唯一的名字,然后你可以在表单发布时在php中检查每一个。 – RightClick
@RightClick他们不需要唯一命名,请检查我的答案。 – Styphon