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 idclient=id and annul !='Y' and activ =1 and gcateg=categid and gpays=paysid' at line 21