MySQL query error messsage appearing in the end