1
1
1
prefix . 'booking_timeslots';
$timeslots = $_POST['timeslot'];
foreach ($timeslots as $time) {
echo $dd = $time['timeslot'];
}
}
?>这是我的完整查询代码。
prefix . 'booking_dates'; //'booking_dates' is a table name which is in the database
$booking_timeslots = $wpdb->prefix . 'booking_timeslots'; //'booking_timeslots' is a table name which is in the database
$year = $_POST['year'];
$month = $_POST['month'];
$days = $_POST['days'];
$timeslots = $_POST['timeslot'];
$data['year'] = $year; // $data['year'] year is a name of column in database
$data['month'] = $month;
foreach ($days as $day) { // $data['month'] month is a name of column in database
$data['day'] = $day; // $data['day'] day is a name of column in database
$wpdb->insert($booking_dates,$data);
$last_record_id = $wpdb->insert_id;
foreach ($timeslots as $timeslot) {
$data_timeslot['bid'] = $last_record_id;
$data_timeslot['time'] = $timeslot;
$wpdb->insert($booking_timeslots,$data_timeslot);
}
}
}
?>当上面的代码执行时,wordpress会给出以下错误。
Illegal string offset 'timeslot' 有人能帮我解决这个问题吗。
发布于 2019-03-04 12:27:27
获得illegal string offset 'timeslot' 是因为 $time is不是数组,而是数组 $timeslots中的一个项。您已经检索了使用$timeslots = $_POST['timeslot'];提交的值。
您的代码还包含其他类型错误。以下是更正后的代码:
1
2
3
prefix . 'booking_timeslots';
$timeslots = $_POST['timeslot'];
// you can use print_r() here
print_r( $timeslots ); // to see what is submitted from form
foreach ($timeslots as $time) {
echo $time;
}
}
?>我希望这能帮到你。
https://wordpress.stackexchange.com/questions/330598
复制相似问题