Please see the attached file and make some comments! I'm open to suggestions!
hmmm... you didn't escape all variables... and, for my 2 pennies - i would have packed the field names into an array... easier to access and not that hard to remember... the rest seems good.