我有一个包含多个字段的表单,所有这些字段都可以相乘
<input type="text" name="child_name[]" />
<input type="text" name="child_age[]" />
<input type="text" name="child_gender[]" />
<input type="text" name="child_school[]" />
我想使用 foreach 向数据库中的表中添加多行,但每次尝试时都会出现错误提示
"Unknown column 'Array' in 'field list'"
当我打印出数据时,它会将所有字段显示为数组,所以我一定是对 foreach 语句做错了,但我不知道是什么
Array ( [child_name] => Array ( [0] => child one [1] => child two) [child_age] => Array ( [0] => 14 [1] => 13 ) [child_gender] => Array ( [0] => male [1] => female ) [child_school] => Array ( [0] => burnside [1] => summer heights high ) )
任何帮助将不胜感激!#
更新
这是我的 foreach 的代码
foreach ($_POST['child_name'] as $child_name)
{
$insert_children_data = array(
'child_name' => $_POST['child_name'],
'child_age' => $_POST['child_age'],
'child_gender' => $_POST['child_gender'],
'child_school' => $_POST['child_school']
);
$insert = $this->db->insert('portrait_children', $insert_children_data);
return $insert;
}