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 'AND Season = AND AgeCategory = AND Type = '' ORDER BY Season DESC, `Group`' at line 1 SELECT * FROM competitions WHERE (Region IS NULL OR REGION = "") AND Level = AND Season = AND AgeCategory = AND Type = '' ORDER BY Season DESC, `Group` 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 'AND Type = '' ORDER BY Season DESC' at line 1 SELECT * FROM competitions WHERE (Region IS NULL OR REGION = "") AND ((Level = 0 AND Season < 2008) OR (Level = 1 AND Season >= 2008)) AND (`Group` IS NULL OR `Group` = 1) AND AgeCategory = AND Type = '' ORDER BY Season DESC