I'm not completely sure, but it probably has something to do with the way you're calling your functions and the way you're assigning values to the variables. The way I troubleshoot something like this is to echo variables at various places in your code, and make small changes at a time. PHP errors tend to not be very informative.