我使用二维数组从自定义字段输入值。像这样
<input type="text" name="education[0][edu_title]" placeholder="Title">
<input type="date" name="education[0][edu_to]" placeholder="To" class="calendar">
值为0的循环更改为1,依此类推。 现在,如果表单已提交,我想获得每个值。
$tableedu = $wpdb->prefix . 'apply_edu';
$education=$pst_data['education'];
$sqldataedu = array();
$count=0;
foreach($education as $edu){
$sqldataedu['edu_title'] = stripslashes($edu[$count]['edu_title']);
$sqldataedu['edu_from'] = stripslashes($edu[$count]['edu_from']);
$sqldataedu['edu_to'] = stripslashes($edu[$count]['edu_to']);
$sqldataedu['edu_institute'] = stripslashes($edu[$count]['edu_institute']);
$sqldataedu['apply_id'] = $lastid;
$wpdb->insert($tableedu, $sqldataedu);
$count++;
}
如何将每个值存储在数据库中
答案 0 :(得分:1)
在数据库中尝试此保存数据。
$education = $_POST['education'];
foreach( $education as $arr ){
$insert_data= array();
$insert_data['edu_title'] = stripslashes($arr['edu_title']);
$insert_data['edu_from'] = stripslashes($arr['edu_from']);
$insert_data['edu_to'] = stripslashes($arr['edu_to']);
$insert_data['edu_institute'] = stripslashes($arr['edu_institute']);
$insert_data['apply_id'] = $lastid;
$wpdb->insert($tableedu, $insert_data);
}