Shouldn't this be if(!$user) and this whole if condition should be after line 62 since you're trying to check whether there's a user linked to this verification code.