Updated sql command, added error message variable.