I am trying to insert the selected values of checkboxes into a mysql database using php. I just can't understand why it's not working because it echoes out all the values fine, but it will only insert the first selected one into the database.
HTML:
<b>Injury type:</b>
Bruise <input type='checkbox' name='InjuryType[]' value='1'><br>
Cut <input type='checkbox' name='InjuryType[]' value='2'><br>
Graze <input type='checkbox' name='InjuryType[]' value='3'><br>
Break <input type='checkbox' name='InjuryType[]' value='4'><br>
Bump <input type='checkbox' name='InjuryType[]' value='5'><br>
PHP:
foreach($_POST['InjuryType'] as $value) {
$insert = mysql_query("INSERT INTO AccidentInjuryLink(InjuryID) VALUES ('$value')");
echo $value;
}
也许该列具有主索引,这意味着所有数字都必须是唯一的,因此只能插入第一个值。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.