如何将复选框值发布到 mysql db 的不同字段。请查看代码。在我的代码中,我有 18 个选项可供选择。我有一个包含 18 个字段的表。我只想将这些值放在相应的列中。这里是编码。
<?php
if(!empty($_POST['subjects'])) {
foreach($_POST['subjects'] as $check) {
echo $check."<br>";
SQL query ???
}
}
?>
<form action="check.php" method="post">
<input type="checkbox" name="subjects[]" value="PakistanStudies" />
<input type="checkbox" name="subjects[]" value="Islamiat" />
<input type="checkbox" name="subjects[]" value="Urdu(SyllabusA)" />
<input type="checkbox" name="subjects[]" value="Urdu(SyllabusB)" />
<input type="checkbox" name="subjects[]" value="Mathematics" />
<input type="checkbox" name="subjects[]" value="AdMathematics" />
<input type="checkbox" name="subjects[]" value="Sociology" />
<input type="checkbox" name="subjects[]" value="ReligiousStudies" />
<input type="checkbox" name="subjects[]" value="EnglishLanguage" />
<input type="checkbox" name="subjects[]" value="EnglishLiterature" />
<input type="checkbox" name="subjects[]" value="Chemistry" />
<input type="checkbox" name="subjects[]" value="Physics" />
<input type="checkbox" name="subjects[]" value="PrinciplesofAccounting" />
<input type="checkbox" name="subjects[]" value="Economics" />
<input type="checkbox" name="subjects[]" value="BusinessStudies" />
<input type="checkbox" name="subjects[]" value="Biology" />
<input type="checkbox" name="subjects[]" value="Statistics" />
<input type="checkbox" name="subjects[]" value="World History" />
<input type="submit" />
</form>