include function does not work in HTML5

Thread Starter

metric_electric

Joined Aug 21, 2013
33
I am trying to make a website using HTML5 and PHP. It's a simple html file with a PHP include ( 'include header.php') statement linking to PHP file.

The text in index.html will show up but nothing from header.php. I have PHP5 downloaded and XAMPP installed on my laptop.

I changed the 'index.html' file to 'index.php', yet it did not fix the problem.

Please help.

Thanks.
 

tshuck

Joined Oct 18, 2012
3,534
There is an error on line 14 where it says...nothing, you haven't shown what it is you are trying to do. No one can help when you don't give us anything to work with.
 

Thread Starter

metric_electric

Joined Aug 21, 2013
33
@tshuck:

I do not get an error message.

my html5 code opens up in google chrome ....instead of displaying the actual website based on the code.

It does this when I include my header file which is 'include head.php'
 

Thread Starter

metric_electric

Joined Aug 21, 2013
33
@mcgyvr, the code is below:
head.php does not run in my browser (chrome)


<!doctype html>
<html lang="en">

<?php
include 'head.php';
?>
<body>

<div id="Big_Wrapper">
<header id="Top_Header">

</header>

<nav id="Top_Menu">
<ul>
<li> Home </li>
<li> <a href="example1.html" STYLE="text-decoration: none"> Register/Login </a> </li>
<li> <a href="html51.html" STYLE="text-decoration: none"> Contact Us </a> </li>
</ul>
</nav>

<div id="New_Div">

<section id="Main_Section">
<div id="aboutMe">
<img src="me.jpeg" height="100"/>

</div>
</section>



<aside id="Side_News">
<h1> News </h1>
</aside>

</div>


<footer id="Main_Footer">
<p> copyright 2013 </p>
</footer>
</div>

</body>
</html>
 

mcgyvr

Joined Oct 15, 2009
5,394
Lets start from the beginning..
What happens when you just type localhost into your browser?.. Do you see the welcome to xampp screen where you can do phpadmin,etc... If not xampp is not started.

Are you saving your files in the htdocs folder under the xampp installation directory?


Then make a new text file and put this into it and save at as phpinfo.php and try to run it
Rich (BB code):
<?php phpinfo(); ?>
Does it report all the php information?
 

Thread Starter

metric_electric

Joined Aug 21, 2013
33
@mcgyvr:

Yes, I see welcome to xampp and I have access to phpmyadmin.

Yes, I am saving my files in the htdocs folder under the xampp directory.

I created phpinfo().php and tried to run it, it did not run..it did not return any information on php installed on my system.
 

sirch2

Joined Jan 21, 2013
1,071
I am confused by your terminology, you say "head.php does not run in my browser"and "I created phpinfo().php".

Firstly no PHP runs in your browser, it is executed by the server when you request the page, the output of the PHP, along with any HTML etc. is then sent to the browser. Are you sure you are pointing your browser to "http://localhost/[filename].php where filename is the name of your PHP file?

On the second point did you really create a file with "()" in its name? - i.e. phpinfo().php.

Sorry if this sounds like nit-picking but this stuff really matters and could be part of the solution to your problem...
 

mcgyvr

Joined Oct 15, 2009
5,394
oh I forgot xampp already has a phpinfo button.

Just go to localhost again and this time hit the "phpinfo()" button in the left menu right under the PHP section

If it doesn't show the information you might have php not installed or not running.
 

Thread Starter

metric_electric

Joined Aug 21, 2013
33
@sirch2:

Sorry about the wrong terminologies, I am new to programing.

Yes I am pointing my browser to "http://localhost/index.html .I include head.php in index.html but the output of head.php is not sent to my browser (chrome).

I also created the file phpinfo().php and no output was sent to my browser
 

sirch2

Joined Jan 21, 2013
1,071
I don't know about xampp but somewhere there should be a log file, errors.log you could try to find it and see if there are any errors.

You could also try putting
Rich (BB code):
error_reporting(E_ALL); 
ini_set('display_errors', 1);
after <?php but before the include statement and again see if it reports errors.

Check that the include file is called 'head.php' and is in the same directory as your index.php. Also note that it has to be index.php, not index.html
 

nerdegutta

Joined Dec 15, 2009
2,689
Hi.

I have this in one of my index.php files:

Rich (BB code):
<?php
require('top.php');
require('config.php');
?>
I have the required files in parentheses and with '-sign.

BTW: I'm running Apache on an ubuntu server.
 

Thread Starter

metric_electric

Joined Aug 21, 2013
33
@tshuck and sirch2

Sorry, my main file is 'html5.php' and so...yes, I saved it with a ".php" extension.

I found the error log file but I do not understand it.

my directory structure is:

file://localhost/Applications/XAMPP/xamppfiles/htdocs/html5.php

and

file://localhost/Applications/XAMPP/xamppfiles/htdocs/head.php

Also, I have a new error:

when I try to log into database 'test' I created on mysql server (localhost/phpadmin), my 'login.php' code outputs on my browser.

my login.php code is:

<?php

include 'connect.php';

if (empty($_POST)==false)
{
$username=$_POST['username'];
$password=$_POST['password'];

echo $username,' ',$password;

if(empty($username)==true || empty($password)== true)
{
$errors[]='You need to enter a username and password';

}
else if (user_exists($username)==false)
{
$errors[]='We can\'t find that username. Have you registered?';
}

}


?>

connect.php:
<?php

mysql_connect('localhost','root','');
mysql_select_db('test');

?>


please help.
 

sirch2

Joined Jan 21, 2013
1,071
actually require() is not a bad idea because it will force an error if the file is not found whereas include() won't. No error would mean no PHP is being interpreted.

What did the error log say? - hit your page and then post the last few lines from the log
 

mcgyvr

Joined Oct 15, 2009
5,394
Type this in your browser address bar
http://localhost/phpinfo.php
Then post a screenshot of what shows up..
If nothing PHP isn't installed/enabled properly.
In addition you can go to localhost and press the "Status" link does it say php is activated..
I really think you don't have php turned on..

Or throw this in a hello.php file and navigate to it..
You should simply see "Hello World" displayed..
Rich (BB code):
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>
You have to ensure php is even being processed.. you haven't proven that yet.
It seems its not.. Thats your PROBLEM.. Nothing will work until you get php installed correctly.

When you a screen like I show in this linked image when you run the phpinfo function then you know its working..
https://dl.dropboxusercontent.com/u/9726802/phpi.PNG
 
Last edited:
Top