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 trialMd Adil
129 PointsI am getting error when I am loading my index page.
I have included all the project files in the shirts folder in the htdocs of the XAMPP. When I am loading the project in the browser, I am getting error like this-
Warning: include(C:/xampp/htdocs/inc/products.php): failed to open stream: No such file or directory in C:\xampp\htdocs\shirts\index.php on line 4
Warning: include(): Failed opening 'C:/xampp/htdocs/inc/products.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\shirts\index.php on line 4
Fatal error: Call to undefined function get_products_recent() in C:\xampp\htdocs\shirts\index.php on line 5
I think, the problem is here- include(ROOT_PATH . "inc/products.php"); I am unable to reload my front page. While I have successfully connected to PDO.
<?php
require_once("inc/config.php");
include(ROOT_PATH . "inc/products.php");
$recent = get_products_recent();
$pageTitle = "Unique T-shirts designed by a frog";
$section = "home";
include(ROOT_PATH . 'inc/header.php'); ?>
<div class="section banner">
<div class="wrapper">
<img class="hero" src="<?php echo BASE_URL; ?>img/mike-the-frog.png" alt="Mike the Frog says:">
<div class="button">
<a href="<?php echo BASE_URL; ?>shirts.php">
<h2>Hey, I’m Mike!</h2>
<p>Check Out My Shirts</p>
</a>
</div>
</div>
</div>
<div class="section shirts latest">
<div class="wrapper">
<h2>Mike’s Latest Shirts</h2>
<ul class="products">
<?php
foreach(array_reverse($recent) as $product) {
include(ROOT_PATH . "inc/partial-product-list-view.html.php");
}
?>
</ul>
</div>
</div>
<?php include(ROOT_PATH . 'inc/footer.php') ?>
Md Adil
129 PointsIn the XAMPP folder, I have the root directory known as htdocs. I have includes all the files in a "shirts" folder inside htdocs. And back in the browser I am trying- localhost/shirts. But it is showing errors as described above. When I tried to change the include function like this-include("inc/products.php"); instead of include(ROOT_PATH . "inc/products.php");. It is loading HTML documents only. I think I am having problem with including files. But it shouldn't occour as I didn't mess with the files.
Kristian Gausel
14,661 PointsYour folder structure should look like this
-htdocs
| - shirts
| - - index.php
| - inc
| - - products.php
Md Adil
129 PointsYes Kristian Gausel , the folder structure is same. I think, the ROOT PATH should be shirts but in my case it is happening like that -C:/xampp/htdocs/inc/products.php. I have removed wherever the ROOT PATH, it is gettin correct. But I want to work the way it has been implemented. Thanks a lot for your support.
Kristian Gausel
14,661 PointsCan you post your config.php contents?
Md Adil
129 Points<?php
// these two constants are used to create root-relative web addresses
// and absolute server paths throughout all the code
define("BASE_URL","/");
define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");
Kristian Gausel
14,661 PointsHave you tried to use relative imports?
include("../inc/products.php");
1 Answer
jason chan
31,009 Pointsinclude 'vars.php';
you don't pass in include in parens it's just quotes
Kristian Gausel
14,661 PointsNot the cause of his problem, as both are allowed.
Kristian Gausel
14,661 PointsKristian Gausel
14,661 PointsYou need to include your file / folder structure for us to be able to help on this, considering the error you get is that the file 'C:/xampp/htdocs/inc/products.php' can't be found