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 '' at line 12-> SELECT a.id_invitado, a.dni, a.nombre, a.apellido_p, a.apellido_m, b.perfil_nombre FROM invitados a LEFT OUTER JOIN perfil b on a.tipo_usuario = b.perfil_codigo where a.id_invitado=