Thank you so much for your help, but I'm still getting the same error on the $query line:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
(FYI - when I remove that one line, everything else prints fine, so I think it's just that...