有沒有簡單的方法來獲取多個複選框的值並將它們存儲在數據庫中?獲取複選框的所有值?
<?php
if(isset($_POST['go'])){
$fruit = $_POST['fruit'].",";
echo $fruit;
// if you selected apple and grapefruit it would display apple,grapefruit
}
?>
<form method="post">
Select your favorite fruit:<br />
<input type="checkbox" name="fruit" value="apple" id="apple" /><label for="apple">Apple</label><br />
<input type="checkbox" name="fruit" value="pinapple" id="pinapple" /><label for="pinapple">Pinapple</label><br />
<input type="checkbox" name="fruit" value="grapefruit" id="grapefruit" /><label for="grapefruit">Grapefruit</label><br />
<input type="submit" name="go" />
</form>
將'name =「fruit」'改爲'name =「fruit []」',移除'$ fruit = $ _POST ...',將'echo $ fruit;'改爲'echo implode(',' $ _POST ['fruit'])' – acm 2011-03-03 15:42:49
將複選框命名爲「name = fruit []」,以便將它們發送到數組 – Michael 2011-03-03 15:43:39