我有以下代码将多行插入到我的自定义WordPress表中。
当我运行表单提交数据并将其插入WordPress数据库时,我收到以下错误消息:
注意:wpdb::prepare的调用不正确。不支持的值类型(数组)。警告:mysqli\\u real\\u escape\\u string()要求参数2为string,
global $wpdb;
$values = array();
$place_holders = array();
$query = "INSERT INTO wp_1com_dc_attedance (customer_id, location_id, funding_source, attend_date, approval_date, attend_am, attend_pm) VALUES";
foreach($_POST as $key => $value)
{
array_push($values, $value);
$place_holders[] = "(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')";
}
$query .= implode(\', \', $place_holders);
$wpdb->query( $wpdb->prepare("$query", $values));
我在$\\u帖子中传递给代码的数组如下所示:
Array (
[customer_id] => Array ( [0] => 2 [1] => 4 )
[locations_id] => Array ( [0] => 1 [1] => 1 )
[funding_source] => Array ( [0] => 1 [1] => 2 )
[attend_date] => Array ( [0] => 2018-02-09 [1] => 2018-02-09 )
[approval_date] => Array ( [0] => 2018-02-08 [1] => 2018-02-08 )
[attend_am] => Array ( [0] => 1 )
[attend_pm] => Array ( [0] => 1 )
)
我希望有人能帮助我,因为我一直在努力解决这个问题,直到今天。