Sorry, I don't have enough time to look at the code, but I looked at the query (thanks VERY much - this helps greatly!)
You didn't mention what database software you are using (MySQL, MS SQL, Access).
I'm going to wild guess at MySQL. If thats the case, you have a collection of '+' you are using to concatenate your strings. MySQL doesn't like that. You can either concantenate the strings in PHP and send MySQL the finished string, or you can use CONCAT() function in MySQL. CONCAT() works by taking each parameter you give it and puts it together as one string so CONCAT("string1", " ", "string2") equals: "string1 string2" (notice the space inbetween the two words).