PHP include help

I’m pretty much a total newbie and have extremely limited code knowledge. I’m creating a website with a boostrap front end, wysiwyg type. I want to create a navbar that will be used on all pages on the site, and am trying to figure out how to use the php include function to allow the server to populate the navbar on all the webpages.

I’ve created a “Navbar.php” file that includes a boostrap navbar only, no css styling.

I’ve created a test webpage “test.php” that only has a paragraph and some text in it.

I have placed this code directly under the in the test.php file, since I want the navbar to be at the top:

<?php include("Navbar.php"); ?>

The problem I’m having is that as soon as I save the test.php file with the php include, the php syntax changes in the code to:

and the php include does not work live. The test.php is not updated with the navbar.

However, when I include a css file in the php include on the test.php file the styling comes through just fine.
The code I use for the css php include is:

<?php include("default.css"); ?>

What am I missing to get the Navbar.php to be included in test.php?

What are you saving this in?

Most likely, you have set up the include file as a separate file. You can not do that. So, lets say you have:

some header stuff... some html code... <?PHP include("Navbar.php"); some more html code... This should work. BUT, you can not use the , or inside the Navbar.php file... It would mess up the HTML layout. Basically, includes do not set up the page, but, just have HTML or PHP code in them. Hope that helps...

I’m the original poster, now registered on this forum.

I’m guessing the problem is with my webpage editor. I’m uing Pingendo, a bootstrap front end. I cannot save .php files only html. So I created “Navbar.html” and then just changed the extension to .php So I need to strip out the

from the php include file. I'll give it a shot.

Notepad++

If you learn to hand code, you learn more in the process. Ditch the editor.

I got the include file Navbar.php properly sorted out, but the main problem is Pingendo. For some reason it changes the php include code to
[php][/php]
on its own. I have to open the file in another code editor in order to properly format the include code, but when I did that everything worked as expected.

LOL, we will consider this one solved!

BUT, listen to Astonechipher and get the FREE Notepad++…

Sponsor our Newsletter | Privacy Policy | Terms of Service