I followed the introduction to use prepare to insert some data to the table. The code is like this:
$wpdb->query(
$wpdb->prepare(
"INSERT INTO {$wpdb->prefix}awpcp_adphotos VALUES
(ad_id, image_name, disabled, isprimary)
(%d, %s, %d,%d)",
$ad_id,
$ad_img,
0,
0));
also, disabled and is_primary should be Boolean. But I am not sure what the data type in here.
I also tried
$wpdb->insert(
'{$wpdb->prefix}awpcp_adphotos', // Table name
array(
'ad_id' => $ad_id,
'image_name' => $ad_img,
'disabled' => 0,
'is_primary' => 0,
), // Columns
array(
'%s',
'%d',
'%d',
'%d'
) // 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.