Jump to content

[SOLVED] proper way to include a file?


simon551

Recommended Posts

Hi, I can't understand why this markup is making my page stop functioning. If I take it out, my javascript will fire, but if I leave it in, nothing.

 

</div>
<div id="menu">
	<?php require_once('../includes/NewMenu.inc.php'); ?>
</div>

 

I don't know for sure this is a javascript or html or php problem... posting here because if I take out the <?php require_once()?> and just leave an empty <div></div> then my page works fine.

 

I'm using dreamweaver which also tells me this is an overlapping or unenclosed tag. but eh?

Link to comment
https://forums.phpfreaks.com/topic/57120-solved-proper-way-to-include-a-file/
Share on other sites

*chuckles at dw*

 

Anyhow the inc.php is not causing the problem the way it is setup is fine and works because the naming scheme lets you know what the file is. Leave that be.

 

Instead post the code for NewMenu.inc.php and maybe even view the source of the page see if there are any errors being hidden.

The menu:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<!--//the functionality for the drop-down was provided here: http://www.alistapart.com/articles/horizdropdowns
--><script type="text/javascript" src="../Scripts/mainmenu.js"></script>
<style type="text/css">
/*@import "../Styles/layout.css";*/
@import "../Styles/menustyle.css";
</style>
</head>
<body>
<p><img src="../Images/vtmlogo.png" width="151" height="75" hspace="2" vspace="0" /></p>
<ul id="nav"> 
  <li><a href="../../../org/userlogin/index.php">Home</a></li> 
  <li><a href="../../../org/Clients/clientlist.php">Clients</a> 
    <ul> 
  <li><a href="../../../org/Clients/clientlist.php">Client List</a> 
      <li><a href="../../../org/Contracts/contractsList_public.php">Contracts</a></li> 
      <li><a href="#">Team</a></li> 
      <li><a href="#">Offices</a></li> 
    </ul> 
  </li> 
  <li><a href="../../../org/Employees/Employee_list_full.php">Employees</a> 
    <ul> 
  <li><a href="../../../org/Employees/Employee_list_full.php">Employee List</a> 
      <li><a href="#">Org Chart</a></li> 
    </ul> 
  </li> 
    <li><a href="#">Projects </a> 
    <ul> 
      <li><a href="../../../org/Projects/projects_allactive.php">All Projects</a></li> 
      <li><a href="../../../org/Projects/projects_byClient.php">Projects by Client</a></li> 
      <li><a href="#">project what</a></li> 
    </ul> 
  </li> 

  <li><a href="../../../org/Timesheets/timesheet_redirect.php">Timesheets</a> 
    <ul> 
      <li><a href="../../../org/Timesheets/timesheet_main.php">New Timesheet </a></li> 
      <li><a href="../../../org/Timesheets/timesheet_redirect.php">Review Timesheets </a></li> 
      <li><a href="../../../org/Timesheets/timesheet_current.php">Current Timesheet</a></li> 
    </ul> 
  </li> 
  <li><a href="../../../org/ExpenseReports/erMain_R.php">Expense Reports </a> 
    <ul> 
      <li><a href="../../../org/ExpenseReports/erMain_C.php">New Expense Report </a></li> 
      <li><a href="../../../org/ExpenseReports/erMain_R.php">Review Expense Reports</a></li> 
      <li><a href="../../../org/ExpenseReports/erDetails_C.php">Current Expense Report</a></li> 
      <li><a href="../../../org/ExpenseReports/review_allexpenses.php">Review Expenses by Date</a></li> 
    </ul> 
  </li> 
</ul> 

<p></p>

<ul>
      <li><a href="../../../org/forum/">Help and Support</a></li> 

</ul>
</body>
</html>

 

No errors found.

Yea, included files should not have the full out html like the file it is bbeing included to, that is where DW will screw you.

 

<!--//the functionality for the drop-down was provided here: http://www.alistapart.com/articles/horizdropdowns
-->
<script type="text/javascript" src="../Scripts/mainmenu.js"></script>
<style type="text/css">
/*@import "../Styles/layout.css";*/
@import "../Styles/menustyle.css";
</style>

<p><img src="../Images/vtmlogo.png" width="151" height="75" hspace="2" vspace="0" /></p>
<ul id="nav"> 
  <li><a href="../../../org/userlogin/index.php">Home</a></li> 
  <li><a href="../../../org/Clients/clientlist.php">Clients</a> 
    <ul> 
  <li><a href="../../../org/Clients/clientlist.php">Client List</a> 
      <li><a href="../../../org/Contracts/contractsList_public.php">Contracts</a></li> 
      <li><a href="#">Team</a></li> 
      <li><a href="#">Offices</a></li> 
    </ul> 
  </li> 
  <li><a href="../../../org/Employees/Employee_list_full.php">Employees</a> 
    <ul> 
  <li><a href="../../../org/Employees/Employee_list_full.php">Employee List</a> 
      <li><a href="#">Org Chart</a></li> 
    </ul> 
  </li> 
    <li><a href="#">Projects </a> 
    <ul> 
      <li><a href="../../../org/Projects/projects_allactive.php">All Projects</a></li> 
      <li><a href="../../../org/Projects/projects_byClient.php">Projects by Client</a></li> 
      <li><a href="#">project what</a></li> 
    </ul> 
  </li> 

  <li><a href="../../../org/Timesheets/timesheet_redirect.php">Timesheets</a> 
    <ul> 
      <li><a href="../../../org/Timesheets/timesheet_main.php">New Timesheet </a></li> 
      <li><a href="../../../org/Timesheets/timesheet_redirect.php">Review Timesheets </a></li> 
      <li><a href="../../../org/Timesheets/timesheet_current.php">Current Timesheet</a></li> 
    </ul> 
  </li> 
  <li><a href="../../../org/ExpenseReports/erMain_R.php">Expense Reports </a> 
    <ul> 
      <li><a href="../../../org/ExpenseReports/erMain_C.php">New Expense Report </a></li> 
      <li><a href="../../../org/ExpenseReports/erMain_R.php">Review Expense Reports</a></li> 
      <li><a href="../../../org/ExpenseReports/erDetails_C.php">Current Expense Report</a></li> 
      <li><a href="../../../org/ExpenseReports/review_allexpenses.php">Review Expenses by Date</a></li> 
    </ul> 
  </li> 
</ul> 

<p></p>

<ul>
      <li><a href="../../../org/forum/">Help and Support</a></li> 

</ul>

 

Try that out, and see where it gets you, you may need to move the style/javascript into the <head> tag or the header.inc.php include.

It should work as long as you have only 1 javascript onload event. It's easier to just create a single onload javascript function and refer to that. Like someone said earlier, your include files shouldn't actually have headers themselves (unless you have exceptions in the php code to handle that situation).

It's easier to just create a single onload javascript function and refer to that

 

hmmm. sounds like a good idea.

 

I have these in 2 files:

 

window.onload=writeCurrName;

window.onload=startList;

 

how would you refer to the onload if I got rid of these and instead just had one:

 

window.onload=loadevent;

 

function loadevent(){

writeCurrName;

startList;

}

 

I tried this and it didn't work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.