0

From this code:

global $wpdb;
$sidebar_table = $wpdb->prefix . 'w3care_sidebar_position'; 
$checkad = $wpdb->get_results( $wpdb->prepare( "SELECT ad_id, sidebar_position, ad_type FROM `%s` WHERE page_id = '11646' AND page_type='page'",$sidebar_table ));

I'm getting the following error:

WordPress database error Table 'wp_rainnews.'wp_w3care_sidebar_position'' doesn't exist for query SELECT ad_id, sidebar_position, ad_type FROM `'wp_w3care_sidebar_position'` WHERE page_id = '11646' AND page_type='page' /* From [siteurl/] in [/urltopluginindex/index.php:855] */ made by .....

But I don't know how this is possible. If I echo $sidebar_table it returns wp_w3care_sidebar_position, so where is this wp_rainnews coming from? And what's with the quotes around it? If anyone can offer any help I would be very appreciative. :)

1

You can't use wpdb::prepare to inject table names - just use "SELECT ... $sidebar_table"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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