2
votes

I was following a demo tutorial but I encountered this error and I fooled everything to the letter so am not sure what to do ...

Warning: include(home.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\shoppingcart\index.php on line 9

Warning: include(): Failed opening 'home.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\shoppingcart\index.php on line 9

This is the index.php file code -

<?php
session_start();
// Include functions and connect to the database using PDO MySQL
include 'functions.php';
$pdo = pdo_connect_mysql();
// Page is set to home (home.php) by default, so when the visitor visits that will be the page they see.
$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : 'home';
// Include and show the requested page
include $page . '.php';
?>
1
home.php file is there in folder path?Vel
Without knowing your apps file structure (where all the files are in relation to each other), it's impossible for us to know what you need to do to fix the issue.M. Eriksson
\-- shoppingcart |-- functions.php |-- index.php |-- home.php |-- products.php |-- product.php |-- cart.php |-- placeorder.php |-- style.css \-- imgs |-- featured-image.jpg |-- camera.jpg |-- headphones.jpg |-- wallet.jpg |-- watch.jpgRobotic EnDcR
That's what the file structure looks like, for now, I found the location to the of the pear file and just place the file in files in there but its not the best of solutions it still not showing the home. page content correctlyRobotic EnDcR

1 Answers

2
votes

First thing to check is that home.php is in the same folder as index.php (so they're next to each other).

Remember that the path "home.php" references a sibling page in the same folder so if the file isn't there, you'll get this error.

On the other hand, if home.php is not meant to be a sibling of index.php and so, is located somewhere else in your directory structure, you'll need to update the value that references it's path