LukePVB Posted May 25, 2014 Share Posted May 25, 2014 I'm having trouble including my navigation bar in my web pages using PHP. This is the script i have included in my web page, but it's not working. <?php include("navbar.php"); navBar(); ?> This is the script in navbar.php enclosing my navigation bar. <? function navBar() { ?> NAVIGATION BAR <? } ?> Help is appreciated. Quote Link to comment Share on other sites More sharing options...
grasshopper31 Posted May 25, 2014 Share Posted May 25, 2014 instead of putting html in a function how bout just take all php out and just leave the html. unless, there other reasons or other things u want to do with navbar, such having more functions. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted May 26, 2014 Share Posted May 26, 2014 <?php function navBar() { echo "NAVIGATION BAR"; } ?> Quote Link to comment Share on other sites More sharing options...
Cornelius Posted May 26, 2014 Share Posted May 26, 2014 (edited) You did everything right.Are the files in the same folder? - navbar.php- main.php Do you have some JS or jQuery (or CSS) code included that wold alter the behavior of the navbar?Instead of navbar code can you put just: <? function navBar() { ?> <p>Test code</p> <? } ?> Edited May 26, 2014 by Cornelius Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 26, 2014 Share Posted May 26, 2014 what do you see in your browser when you do a 'view source' of the resulting page? if you see the actual contents of the navbar.php file, i.e. the php function definition, the problem is the use of short opening <? tags. you should always use full opening <?php tags. Quote Link to comment Share on other sites More sharing options...
LukePVB Posted May 26, 2014 Author Share Posted May 26, 2014 instead of putting html in a function how bout just take all php out and just leave the html. unless, there other reasons or other things u want to do with navbar, such having more functions. I want to build my site using this PHP script so when i want to add more links to the navigation bar on all pages, I can by only changing one page. what do you see in your browser when you do a 'view source' of the resulting page? if you see the actual contents of the navbar.php file, i.e. the php function definition, the problem is the use of short opening <? tags. you should always use full opening <?php tags. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta charset="utf-8"> <link href="css/main.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <header> I use was trying to use the same script to load my header.That script seem to be stopping the rest of the HTML from loading. The script I was using to load my header is the following <?php include("header.php"); echo $header; ?> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 26, 2014 Share Posted May 26, 2014 you are likely getting a fatal parse or runtime error in the code in your included file. you NEED to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini on your development system so that php will HELP you by reporting and displaying the errors it detects. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.