$wpdb The query does not contain the correct number of placeholders

Question

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.

0
user19103974 1 day 2022-09-23T16:30:06-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse