简体   繁体   中英

Two php includes in one html file

I am getting my hands on webdev at the moment and am facing a strange issue: I have two php includes in one html file. Unfortunately only the first include is working, the second one seems to stop transfering the html code to browser. There is no mistake in the corresponding php files since the html file is loading proplery, once I disable one of the includes. Can somebody explain this issue?

 ... <div class="wrapper"> <div class="left"> ... </div> <div id="div_table" class="center"> <table id="mytable" cellspacing="0" width="100%"> <?php include("../php/table_data.php"); ?> </table> </div> </div> <div id="div_add_element" title="Add element"> <form id="form_add_element"> <table> <tr> <td><label for="id_name">Name</label></td> <td><input id="id_name" name="name" type="text" width="30"> </input></td> </tr> <tr> <td><label for="id_edition">Edition</label></td> <td> <select id="id_edition" name="edition"> <?php include("../php/option_editions.php"); ?> </select> </td> </tr> </table> </form> </div> 

You cant put PHP code in HTML.

So if you have index.html you can't add php code. Change the name to index.php.

And then use:

include('FILEPATH');

There is no mistake in the corresponding php files since the html file is loading proplery, once I disable one of the includes.

Your reasoning defeats your conclusion. If removing one of the includes makes your HTML work, then your problem is with the include . If you are accurate in saying that the pasted code is inside an HTML file, then you need to change it to PHP, as you cannot use PHP code inside an HTML file.

When you made sure that your include calls are called inside a PHP file, you need to make check every element in the following list:

  • your file paths are always correct. You are using relative paths, which assume that the path relative to your current folder is correct. You might assume that this is the case because your paths are correct from your starting folder, but the files might use chdir which changes the current folder. getcwd might help you in determining the directory you use
  • the files required or included by your included files include or require only existing files you have access permission to
  • you do not include or require the same function or class twice
  • you have access permission to all the files you intend to include
  • there are no PHP errors when you include your files
  • the PHP in your files do the thing you desire
  • if the PHP files generate HTML, then the HTML you end up with is correct

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