While we appreciate the fact that you used the Code tags, in this forum pressing the Code tag button creates both start and end tags, not just one or the other. Therefore, you have an empty code box, followed by your code (not in a code box), followed by another empty code box.

In regards to your code, I'm sorry to say that I can't see anything wrong with it, so I have no idea as to why it's not working (although I can confirm that it's not working by my own testing)