php include function leaves my page blank -
when try include php menu and/or footer onto page, whole page shows blank. if take same code , put index.php html works fine. doing wrong?
here's index page:
<div id="navigation"> <?php include 'menu.php'; ?> </div> <div id="content"> <?php echo "hello world!"; ?> </div> <div id="footer"> <?php include 'footer.php'; ?> </div>
ok , here's menu.php , footer.php pages: menu:
<?php echo "<ul> <li><a href="index.php">main</a></li> <li><a href="info.php">php info</a></li> <li><a href="wda1.php">assignment 1</a></li> </ul>"; ?>
footer:
<?php echo "$filename = 'index.php'; if (file_exists($filename)) { echo "this page last modified: " . date ("f d, y h:i:s.", filemtime($filename)); }"; ?>
the tutorial @ http://www.w3schools.com/php/php_includes.asp lead me believe i'm doing correctly, apparently not case. appreciated, thank you.
here:
first file: (index.php
presume?)
<div id="navigation"> <?php include 'menu.php'; ?> </div> <div id="content"> <?php echo "hello world!"; ?> </div> <div id="footer"> <?php include 'footer.php'; ?> </div>
menu:
<?php echo '<ul> <li><a href="index.php">main</a></li> <li><a href="info.php">php info</a></li> <li><a href="wda1.php">assignment 1</a></li> </ul>'; ?>
footer:
<?php echo $filename = 'index.php'; if (file_exists($filename)) { echo "this page last modified: " . date ("f d, y h:i:s.", filemtime($filename)); } // else not required show nothing if file doesn't exit // can remove it, it's optional else{ echo "<br>this not index.php. still show filename above this."; } ?>
here summary of mistakes made:
1) echo "<ul><li><a href="index.php">main</a></li>
- you either escape double quotes
\"
hyperlinks, or wrap echo using single quotes shown in answer above; it's lot less work.
then:
2) echo "$filename = 'index.php'; ... }";
- you're wrapping entire code in double quotes, hoping that; echo. generate parse error, carbon copy of did in point #1.
- removing first double quote before
$filename
getting rid of last 1}";
troubleshooting tip(s)
add error reporting top of file(s) error_reporting(e_all); ini_set('display_errors', 1);
signal errors found in code , guide along.
for more information on error reporting, visit php.net:
Comments
Post a Comment