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 trialAlan Guevara
7,247 PointsWhy isn't ROOT_PATH working?
When I inlcude the ile like this it gives me a server error:
require(ROOT_PATH . "inc/database.php");
I did declare he constant like this: define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");
However it does work if I include the file just like this:
require 'nc/database.php';
2 Answers
Andrew Shook
31,709 PointsAlan, are you defining the root path in the file you are trying to include database.php in, or is root path defined somewhere else. If it's defined somewhere else, then you need to include the file it's defined in before you try to use it. Also, are you sure database.php is located inside the inc folder or is it located inside of another folder inside the inc folder. I know these might sound like dumb questions, but something you need to double check things just to make sure.
Alan Guevara
7,247 PointsThanks for the response Andrew, I had defined the constant ROOT_PATH in the config.php file since it is where Randy seems to have declared it. So, do I have to define it in the file where I am doing this: require(ROOT_PATH . "inc/database.php"); ?
Do I really have to use ROOT_PATH? What is the purpose? What if I only leave this:
require 'nc/database.php';
The latter seems to work just fine.
Thanks again.
Andrew Shook
31,709 PointsAre you properly including the config.php? If it's declared in the config.php you have to include it in every file you want to use it in.