Not sure, your code looks fine. But, in PHP, usually you define your functions before you use them.
So, perhaps just moving the functions to the top of the page might fix this.
In Javascript it does not matter where you put your functions, but, PHP seems to like them defined before using them. Try that and let us know...