Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Using PHP with MySQL Querying the Database with PHP Modifying Model Code

Kaetlyn McCafferty
Kaetlyn McCafferty
12,193 Points


I seem to be having issues with the model code in the 'Using PHP with MySQL' course due to the ROOT_PATH. What I've done is downloaded the files from the course and moved them into a folder titled "shirtsformike" in my htdocs. The database and database.php files I created up until this point worked perfectly well, but when I tried to load the model code (locally, at http://localhost:8888/shirtsformike/ ) I started encountering issues - nothing was loading other than a big connection error. I put in some error handling and started commenting out sections and discovered that the issues were being caused by file paths.

So, I went through the code and rewrote everything that called upon the ROOT_PATH with a normal path. For example;

include(ROOT_PATH . 'inc/footer.php');

I changed the above code to the following


Once I replaced every single one of these include(ROOT_PATH); instances with just a file path, everything worked just fine. I'm not sure if it's worth noting or not, but the BASE_URL isn't giving me any problems, just ROOT_PATH.

I realize that the ROOT_PATH is located in the config.php file but I'm not sure how to modify it to work correctly (I don't know what/where $_SERVER or DOCUMENT_ROOT are). It looks like this;

define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");

I tried changing that last "/" to "./" thinking maybe that's what were missing, but it had no effect. So, what am I missing here?

A million thanks for any help or suggestions! I hope this question makes sense.

1 Answer

Instead of using $_SERVER["DOCUMENT_ROOT"] in the constant ROOT_PATH can you try using $_SERVER['HTTP_HOST'] instead, So:

define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");

change for

define("ROOT_PATH",$_SERVER["HTTP_HOST"] . "/");

Also try echo ROOT_PATH see what's the value

$_SERVER is a php global array created by the server that contains the header information such as server document path etc. $_SERVER["DOCUMENT_ROOT"] and because you're working in a local environment the value must be something like C:.. instead of http://localhost...