Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

db connection problem

Hey I am learning php authentication system but whenever i click on login button something went wrong with db connectivity dur to which i got error

Notice: Undefined variable: db in C:\xampp\htdocs\registration\core\functions\users.php on line 7

Fatal error: Call to a member function prepare() on null in C:\xampp\htdocs\registration\core\functions\users.php on line 7

but when in core>functions>users.php I include db connectivity seperately in each function the code work well.

I am working on mylocalhost and I don't know how to use database in workspace so I simply upload all my files structure here in workspace https://w.trhou.se/xzryd65yoe.

Please help me out

1 Answer

Simon Coates
Simon Coates
28,694 Points

might be scope. Does behavior change if your include line

global $db;

? The $db looks like it is defined globally such that it won't be available in a function scope.