You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) * cos(radians(th.longitude)-radians()) + sin(pi()/2-radians(90-th.latitude)) ' at line 5 in SELECT th.*, "Hipodromo de Sanlucar de Barrameda" as landmark_name, tr.region_name as city, ROUND(3958.78 * acos(cos(pi()/2-radians(90-th.latitude)) * cos(pi()/2-radians(90-)) * cos(radians(th.longitude)-radians()) + sin(pi()/2-radians(90-th.latitude)) * sin(pi()/2-radians(90-))) , 2) as distance FROM tbl_hotel as th LEFT JOIN tbl_region as tr ON th.region_id = tr.region_id WHERE th.active = 1 HAVING distance < '5' ORDER BY distance ASC LIMIT 0,50