简体   繁体   中英

PHP Include a file in a included file?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM