我需要插入技术来将多个相同形式的数组插入到一个表中,我尝试了以下代码。
输入.html
<form method="post" enctype="multipart/form-data" action="action.php">
<div>
<input type="checkbox" name="feel[]" value="Worried" id="feel1">
<label for="feel1">Worried</label>
</div>
<div>
<input type="checkbox" name="feel[]" value="Scared" id="feel2">
<label for="feel2">Scared</label>
</div>
<div>
<input type="checkbox" name="problem[]" value="Worried" id="problem1">
<label for="problem1">Worried</label>
</div>
<div>
<input type="checkbox" name="problem[]" value="Scared" id="problem2">
<label for="problem2">Scared</label>
</div>
</form>
动作.php
<?include 'include/connect.php';
for($i=0;$i<count($_POST["feel"]);$i++)
{
$array=array("self_assessment_emotion"=>$_POST['feel'][$i]);
$feel = $db_obj->insert($array,"tbl_self_assessment");
}
for($i=0;$i<count($_POST["problem"]);$i++)
{
$array=array("self_assessment_physical"=>$_POST['problem'][$i]);
$problem = $db_obj->insert($array,"tbl_self_assessment");
}
?>
我得到这个输出:
这就是我需要的: