Fatal error: Call to a member function query() on null
First, you declared $db outside the function. If you want to use it inside the function, you should put this at the begining of your function code: And I guess, when you wrote: what you really wanted was: