-1

I read 3 articles about it and couldn't fix it.

Notice: Undefined variable: DBH in C:\xampp\htdocs\certa\sandbox.php on line 18

Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\certa\sandbox.php on line 18

It just happened randomly, don't know what code caused it..`

I cant get the code tags to properly display my code. Its giving a lot of trouble. So here is the paste bin (sorry for giving an external link.)

http://pastebin.com/cEC7FdNZ

My config file, is just connecting to MySQL using PDO , and $DBH is that database handler.

JGreen
  • 11
  • 1
  • possible duplicate of [pdo - Call to a member function prepare() on a non-object](http://stackoverflow.com/questions/5346186/pdo-call-to-a-member-function-prepare-on-a-non-object) – Rizier123 Mar 04 '15 at 10:06

1 Answers1

1

Put global $DBH; as the first line in your function.

The function does not have access to variables outside it, with global you can work around this issue. Later on it would be beter to switch to OOP, because global itself is also not a good solution.

Blaatpraat
  • 2,829
  • 11
  • 23
  • thanks, that fixxed. Mind going baout how I can use OOP? – JGreen Mar 04 '15 at 10:00
  • It's a whole other way of thinking. It's not just as easy as saying what you should do. I can only advise you to find a good guidance (online or in books). – Blaatpraat Mar 04 '15 at 10:02