WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I followed the introduction to use prepare to insert some data to the table. The code is like this:

                "INSERT INTO {$wpdb->prefix}awpcp_adphotos VALUES
                (ad_id, image_name, disabled, isprimary)
                (%d, %s, %d,%d)",

also, disabled and is_primary should be Boolean. But I am not sure what the data type in here.

I also tried

'{$wpdb->prefix}awpcp_adphotos', // Table name
    'ad_id' => $ad_id,
    'image_name' => $ad_img,
    'disabled' => 0,
    'is_primary' => 0,
), // Columns
) // Explicit formatting


But I haven't got any luck yet. There is no error message when I run the code.

Okay, I found answers in somewhere else. it should be like this:

    $wpdb->insert($wpdb->prefix.'awpcp_adphotos', array(
 'ad_id' => $ad_id,
 'image_name' => $image_name,
 'disabled' => $disabled,
 'isprimary' => $isprimary,

I was confused with prefix format.

share|improve this question
Do you have debugging information? – s_ha_dum Jun 21 '13 at 18:46
Have you looked at $wpdb->last_error to find what the error message is? – Otto Jun 21 '13 at 18:48
Guys, come on. You don't need debug to see that these queries are not correct ;) – Krzysiek Dróżdż Jun 21 '13 at 18:53
up vote 1 down vote accepted

I'm pretty sure that first SQL query isn't correct SQL (insert has different syntax) ;) It should be:

INSERT INTO {$wpdb->prefix}awpcp_adphotos (ad_id, image_name, disabled, isprimary) VALUES (%d, %s, %d,%d)

In second example, I'm almost sure that ad_id is not string, and image_name is not a number. Of cours I'm only guessing, because I haven't seen this table definition.

Remember that you can always turn error reporting for wpdb on. Just put this line in your code and you will see wpdb errors:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.