Error checking when preparing statement