有没有一种简单的方法来获取多个复选框的值并将它们存储在数据库中?
<?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