Mr Shabir
Mr Shabir

Reputation: 173

WordPress database error: You have an error in your SQL syntax

Below WordPress database error is coming:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 for query SELECT * FROM wp_author_followers WHERE author_id = made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'),

Here is my code.

global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}author_followers WHERE author_id = $author_id", OBJECT );
$followcounter = count($results);
return $followcounter;

Upvotes: 0

Views: 9404

Answers (2)

Mr Shabir
Mr Shabir

Reputation: 173

Everything was correct, Just Author ID was not there, I have fixed this issue. Thanks for your attention and help.

Upvotes: 1

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

echo "SELECT * FROM {$wpdb->prefix}author_followers WHERE author_id = $author_id";

Try to echo $author_id before the SQL query, and check SQL statement after replacing $author_id with its value.

Thanks

Upvotes: 0

Related Questions