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. Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/ 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. Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/#findComment-1480832 Share on other sites More sharing options...
QuickOldCar Posted May 26, 2014 Share Posted May 26, 2014 <?php function navBar() { echo "NAVIGATION BAR"; } ?> Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/#findComment-1480839 Share on other sites More sharing options...
Cornelius Posted May 26, 2014 Share Posted May 26, 2014 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> <? } ?> Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/#findComment-1480841 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. Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/#findComment-1480887 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; ?> Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/#findComment-1480903 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. Link to comment https://forums.phpfreaks.com/topic/288766-trouble-including-html-using-php/#findComment-1480904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.