well considering there arent 35 lines, repost your edited code, so one of the gurus can have an AHA moment
its likely simple, a mismatched set of quotes, but hard to diagnose from an errormessage that has more lines than the code sample
To get this kind of code working ... There are to many " and ' that can make it go wrong and in the end you don't see anymore what is going on. So in the following 3 steps, I start with normal html code, rewrite it to php and finally insert the variable. The code is tested and works.