What is wrong in my code? It doesn't get the count but it is inserting into the database.
function r_rate_recipe()
{
global $wpdb;
$output = array('status' => 1);
$post_id = absint($_POST['rid']);
$rating = round($_POST['rating'], 1);
$user_ip = $_SERVER['REMOTE_ADDR'];
$rating_count = $wpdb->get_var(
"SELECT COUNT(*) FROM '" . $wpdb->prefix . "racipe_ratings'
WHERE recipe_id='" . $post_id . "' AND user_ip='" . $user_ip . "'"
);
if ($rating_count > 0) {
wp_send_json($output);
}
$wpdb->insert(
$wpdb->prefix . 'racipe_ratings',
array(
'recipe_id' => $post_id,
'rating' => $rating,
'user_ip' => $user_ip
),
array('%d', '%f', '%s')
);
$output['status'] = 2;
wp_send_json($output);
}