Watty, even after looking over your code, I had to do the parenthesis counting check. First, count all parenthesis (and/or brackets, depending on your situation) that are open '('. Then count the comparable parenthesis that are closed ')'. If they don't match up (i.e.: 3v4), you're missing one. After I fixed it, I still thought it looked funny and had to double check myself.

As for your math, output the variables in a mathematical equation form. If you're doing the math within MySQL, use a SELECT query instead, get the variables, and do the math (if possible - if not, select the fields and output them to see what form they're in).
Sometimes it helps to see, visually, the math you're doing.
i.e.:
Original: echo $variable1 - $variable2;
Convert to: echo $variable1, ' - ', $variable2, ' = ', ($variable1-$variable2);
...or if you have a more capable PHP IDE to work with, you can follow the stack, as it does this for you.