falkencreative wrote:I looked over your code a bit, and I have to admit I'm a bit confused... Maybe it's that you haven't posted the entire files, but they seem to be set up wrong. For example, with those two files you have two sets of body tags... it just isn't what I would expect.
For example, here is a brief example showing a php include used to include navigation elements:
Index.php file:
<!-- doctype here -->
<html>
<head>
<title>title</title>
</head>
<body>
<div id="wrapper">
<div id="header">
<!-- logo here -->
<?php include("nav.php"); ?>
</div>
<div id="content">
<!-- content here -->
</div>
</div>
</body>
</html>
nav.php:
<ul id="nav">
<li>nav item</li>
<li>nav item</li>
<li>nav item</li>
<li>nav item</li>
</ul>
I was wondering the same thing. From what little I know about PHP and programming in general, the include file should contain just the navbar code and nothing else, as you have rightly shown above, because if the navbar were to be wrapped in body tags, the resulting index.php source would have body tags contained within body tags. (A page can only contain one set of body tags, and html tags for that matter, isn’t that right?).
But now that I mention it, something along the same line of reasoning has me puzzled about Includes: Last night, while viewing the PHP Includes video (part 2) and practicing my coding, I noticed that in order for the declared variable contained in footer.inc.php to work, it must be wrapped in PHP tags. But that doesn't make any sense to me because if I were to put that section straight into my_page.php without using the include function, it would generate an error (as expected) because there would be PHP tags wrapped in PHP tags:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Killerphp.com Video Tutorial</title>
</head>
<body>
<h1>PHP INCLUDES</h1>
<p>
<?php
//The line of code below would cause a parse error because PHP tags can’t be contained within PHP tags. Yet if I were to place this SAME line of code into an include file (whether that be footer.inc.php, footer.inc or even just footer.txt) and use the include function, no error would be generated and "fish" would be printed to the source. How come?
<?php $secret_password = "fish"; ?>
print $secret_password;
?>
</p>
</body>
</html>
Clearly, there's something fundamental about includes that I’m not getting.