I have to work with the page to see what is going on. If you can put it on a live url I can take a look. I don't see any issue with the code you supplied. I may be overlooking something, but I can't imagine what it would be.
If I could view the error on a live site and debug it then I'm sure I could figure it out, but as it is I don't have a solution since I don't see a problem.