I have the following code to insert multiple rows into my custom WordPress table.
When I run the form to submit the data and insert it to the WordPress database I get the this error message:
Notice: wpdb::prepare was called incorrectly. Unsupported value type
(array).
and
Warning: mysqli_real_escape_string() expects parameter 2 to be 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));
The array I am passing to the code in the $_POST is as follows:
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 )
)
I hope somebody can help me as I have been working to try and fix this for the best part of today.