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 CHAR_LENGTH(f.cLogo)>4 ORDER BY nSponsor DESC, RAND() DESC LIMIT 5' at line 1 Your query was: SELECT nUserID, cName, cEmail, nPoints FROM tblUsers WHERE cUsername = '' AND cPassword = ''