There are two things needed.
1. A php script, containing a number of string variables is being used to generate one large string. I can't seem to follow the logic myself as to how the particular final string is ending up as it is and not what I want it to be. I think this should be a pretty easy fix for anyone who knows PHP well.
2. I need a little subfunction written that checks to see if an item is in the database before executing a particular command. Again this should be a piece of cake for anyone that knows PHP and SQL.