Reputation: 220
I am using a two dimensional array for inputting value from custom field. like this
<input type="text" name="education[0][edu_title]" placeholder="Title">
<input type="date" name="education[0][edu_to]" placeholder="To" class="calendar">
It is a loop that is value of 0 is changed to 1 and so on. Now if the form is submitted i want to get each value.
$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++;
}
how can i store each value in database
Upvotes: 0
Views: 235
Reputation: 1709
Try this save data in database.
$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);
}
Upvotes: 1