Fixing the php logic

Stop if there's something going wrong