Hello, i am a beginner php dev and and currently following the beginner series here on laracast.
I ran in to this problem where i try to require files in another directory different from that of the file am calling from.
The sample code and the server response are as shown below.
<?php
require('core/config.php');
$messages_q = "SELECT * FROM communications";
if ($result_message = $conn->prepare($messages_q)) {
$result_message->execute();
$messages_arr = $result_message->fetchAll();
}
require 'views/index.view.php';
resoponse
Warning: require(core/config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\HogwartsStudentPortal\controllers\index.php on line 3
Fatal error: require(): Failed opening required 'core/config.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\HogwartsStudentPortal\controllers\index.php on line 3
So, in the same location as index.php, you should have a core folder.
Both index.php and the core folder should be in the same controllers folder to make your code work.
However, maybe it makes more sense to have the core folder directly in HogwartsStudentPortal. In this case, you could use: