1

I want to include a file in an included file.

I have a file named acp.php in the directory Pages/cms/src/acp.

In this file I included the file connect_get_data.php in the directory Pages/cms/src/acp/tools, which is to print the database output for the requested page.

In this file I included the Database connection file which is named connection.php in the directory Pages/cms/src/tools.

Here are my include statemants:

acp.php - include("./tools/connect_get_data.php");

connect_get_data.php - include("../../tools/connection.php");

and here is the Error it caused:

<br />
<b>Warning</b>:
include(../../tools/connection.php): failed to open stream: No such file or directory in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>2</b><br />
<br />
<b>Warning</b>:
include(): Failed opening '../../tools/connection.php' for inclusion (include_path='C:\xampp\php\PEAR') in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>2</b><br />
<br />
<b>Notice</b>:
Undefined variable: db in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:
mysqli_query() expects parameter 1 to be mysqli, null given in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:
mysqli_fetch_object() expects parameter 1 to be mysqli_result, null given in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>5</b><br />
<br />
<b>Notice</b>:
Trying to get property 'Content' of non-object in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>6</b><br />
<br />
<b>Notice</b>:
Undefined variable: db in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>7</b><br />
<br />
<b>Warning</b>:
mysqli_close() expects parameter 1 to be mysqli, null given in <b>C:\xampp\htdocs\Pages\cms\src\tools\connect_get_data.php</b> on line <b>7</b><br />

But if I open the connect_get_data.php in my browser it works fine...

I hope some one her can help me with my issue.

2
  • 2
    Use absolute paths in your includes, or use $_SERVER['DOCUMENT_ROOT'] and use the path from there. By just using dots, it will attempt to access the file relative to the current URL path. Commented Apr 10, 2019 at 13:23
  • 2
    ^ or the magic constant __DIR__ Commented Apr 10, 2019 at 13:26

1 Answer 1

1

There is a path error instead of include("../../tools/connection.php"); use include("../tool/connection.php");.

this will work for you. There is a path error in your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.