Include/Require problems w. HTML

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

spoot088
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Jul 20, 2014 1:36 pm

Include/Require problems w. HTML

Postby spoot088 » Sun Jul 20, 2014 1:43 pm

I am attempting to use the php include or require functions to recall a header and footer file. I create the header.php file, use <?php require './header.php';?> in the file I want to recall the header html information. The problem is when I use certain html it ruins everything. I can recall text.. text with simple tags like <b>, <u>... but if I use a link or image tag it ruins the whole thing and nothing appears.

I don't know where I'm going wrong?

BigZ1981
New php-forum User
New php-forum User
Posts: 7
Joined: Sat Jul 19, 2014 11:24 pm

Re: Include/Require problems w. HTML

Postby BigZ1981 » Sun Jul 20, 2014 3:49 pm

I would leave the ./ out of the filename as you don't need it: <?php include 'header.php'; ?>
I've never had an issue with anchor or image tags, so make sure you're closing tags that need to be closed & if you're adding other php code within that file, you check for any syntax errors. I had an issue with my contact form page not displaying, and I couldn't figure out why. I had to go through my code line by line to find out that I was missing a closed parentheses within one of my if statements. I had to read each line and statement to make sure I was closing everything properly. One small thing like that (which is hard to spot by just skimming through the code) will throw the whole thing off.

spoot088
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Jul 20, 2014 1:36 pm

Re: Include/Require problems w. HTML

Postby spoot088 » Sun Jul 20, 2014 4:09 pm

i fixed it. the problem was in the header.php file. I had placed my html coding in an echo command. It turns out all you have to do is place the html in the header.php file by its self.

BigZ1981
New php-forum User
New php-forum User
Posts: 7
Joined: Sat Jul 19, 2014 11:24 pm

Re: Include/Require problems w. HTML

Postby BigZ1981 » Sun Jul 20, 2014 9:45 pm

Yeah. Glad you figured it out. That include function is nifty...keeps you from having to change 50 million pages that have the same menu, title image, footers, etc. Heck, I even have an include within an include...which I probably don't need, but it helps me isolate the code I want to edit. For example...I have a similar include for headers.php & within that file I have an include for menu.php...now that I'm mentioning this, I may actually end up just putting my menu code in my headers.php file...it's not like it's a huge chunk of code in there anyway. Anyway, happy coding. :D

jonbras1
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Aug 27, 2014 7:48 am

Re: Include/Require problems w. HTML

Postby jonbras1 » Wed Aug 27, 2014 7:58 am

I need some help with this. I created an index.php page and I inserted an include statement that referred to a header.html page. It works when working it in MS Webmatrix but when I put it on my server I only get my index.php page. My include statement will not get the header.html page. What am I doing wrong?

Here is my index.php file:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Braswell Electric</title>
<link rel="stylesheet" href="braswellelectric.css">
</head>

<body>
<div>
<?php include('/includes/header.html');?>
<?php include('/includes/aside.html');?>

<article class="About">
<header class="AboutHeader">
<h2>About Us</h2>
</header>
<p><b>Braswell Electric</b> is a family business owned and operated by Jim and Joyce Braswell located in Sylacauga, Alabama. Braswell Electris has been in business in Sylacauga for 25 years and covers the greater Talladega County area. We do new homes, remodels, or any small electrical issues you may have. We are licensed and insured and we are here for your residential needs.</p>

<img src="pics/Coach Light.jpg" alt="Coach Light" >
<img src="pics/Outside Plug.jpg" alt="Outside Plug">
<img src="pics/Service.jpg" alt="Service">

</article>
</div>
</body>
</html>

Here is my header.html file

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>

</head>
<body>
<header class="Header">
<h1 style="display: none">Braswell Electric</h1>
<img src="pics/lightning1.jpg" alt="Header Pic">
</header>

</body>
</html>

afelipeor
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Apr 29, 2014 11:16 am

Re: Include/Require problems w. HTML

Postby afelipeor » Wed Aug 27, 2014 8:18 am

Did you add the Files you want to include correctly in their directories? You could (and probably should) change their extensions to .php instead of leaving them in .html

jonbras1
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Aug 27, 2014 7:48 am

Re: Include/Require problems w. HTML

Postby jonbras1 » Wed Aug 27, 2014 2:14 pm

I am new with this. I changed all of the files to .php and it still did't work. You asked if I added the files I wanted to include to their directories? I have the 2 files, header.html and aside.html saved with the rest of the files. I did have them in a separate folder called includes and that did not work either.

Just so you know my site will work when using webmatrix, before putting on the server. But after I put it on the server it will only read my index.php file. It is like it is skipping my include statements.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 5 guests