Gibblefish
Gibblefish

Reputation: 61

php include echo error

I am trying to use the php include tag for my header and footer, and can't seem to find the problem. My include code is fine in my index file, and my header.php file shows no errors, but t doesn't include the file when I preview it in a browser. Is this an easy fix or am I missing something.

My index.php file include snippet

<div id="container">
   <?php include('include/header.php');?>
<div id="body">

My header.php file code

<?php 
echo <<<END
<header>
<nav>
<li onclick="location.href='index.html';"  style="cursor:pointer;"><a href="index.html" class="active">Home</a></li>
<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Contact</a></li>
<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">FAQ's</a></li>
<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Product Solutions</a></li>
<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Services</a></li>
<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Request a Quote</a></li>
</nav>
</header>
END;
?>

Upvotes: 1

Views: 278

Answers (4)

mark
mark

Reputation: 89

Change this line:

<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">FAQ's</a></li>

With this:

<li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">FAQ\'s</a></li>

The error was this:

FAQ's

And I changed it to this:

FAQ\'s

Upvotes: 0

Exayy
Exayy

Reputation: 620

It seems ok on my computer. Are you sure that's your header file is the right directory? It should be:

---- index.php
---- include (directory)
     |---- header.php

If it's ok you must file permissions and be sure that index can include the header file.

Why do you need to use heredoc syntax?

Upvotes: 2

Jason
Jason

Reputation: 1079

Why not do this instead:

<?php
    ... some code ...
?>

<header>
    <nav>
        <li onclick="location.href='index.html';"  style="cursor:pointer;"><a href="index.html" class="active">Home</a></li>
        <li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Contact</a></li>
        <li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">FAQ's</a></li>
        <li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Product Solutions</a></li>
        <li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Services</a></li>
        <li onclick="location.href='#';"  style="cursor:pointer;"><a href="#.html">Request a Quote</a></li>
    </nav>
</header>

<?php ... more code ... ?>

<!-- more html -->

You don't need echo. Any HTML not within tags are automatically outputted anyways. Remember that PHP is based on HTML. You can think of PHP as HTML with <?php?> tags mixed in.

Upvotes: 0

may saghira
may saghira

Reputation: 564

what do you mean by

echo <<<END ???

however the file header.php is in a separate folder ? look at in the console to see if it can locate the file or not... for me i used to work with :

require_once("include/header.php");

Upvotes: -1

Related Questions