Fixed $db reference, SQL query missing marentheses