Try to define ID outside of the if statement - if the statement is false, then ID does not exist.
I'm not sure why but often when I have declared something inside of a loop or if/switch statement, it can not be used by other variables. So try defining it before the if statement.