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 (machine_categorie= 'stapelaar' ))' at line 1 - SELECT MIN(machine_id) AS prevID FROM machines WHERE ((machine_id > ) AND (machine_categorie= 'stapelaar' ))