這是我的表單,類別來自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