Kaetlyn McCafferty12,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("BASE_URL","./"); 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.
Sergio Alen26,726 Points
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"] . "/");
define("ROOT_PATH",$_SERVER["HTTP_HOST"] . "/");
Also try echo ROOT_PATH see what's the value