$wpdb The query does not contain the correct number of placeholders
I am trying to push some data to a custom table in my WordPress install, but I am getting the error The query does not contain the correct number of placeholders
and I’m not sure why. Here is my query:
$sql = $wpdb->prepare(
'INSERT INTO products
(`name`, `color`, `price`)
VALUES
(%s, %s, %s)
ON DUPLICATE KEY UPDATE
price = %s',
$name,
$color,
$price
);
$wpdb->query($sql);
The exact error is this:
Notice: Function wpdb::prepare was called incorrectly. The query does
not contain the correct number of placeholders (4) for the number of
arguments passed (3).
I am not sure why it is looking for 4 placeholders, because I am only trying to insert/update 3 columns, so it should only be looking for 3 placeholders/arguments.
Leave an answer