Jump to content

trouble including html using PHP


LukePVB

Recommended Posts

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
Share on other sites

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 by Cornelius
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.