include function does not work in HTML5

Discussion in 'Programmer's Corner' started by metric_electric, Jan 2, 2014.

  1. metric_electric

    Thread Starter New Member

    Aug 21, 2013
    19
    0
    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.
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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.
     
  3. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Agreed.

    I learned almost everything I know about website development from that site!:p
     
  5. metric_electric

    Thread Starter New Member

    Aug 21, 2013
    19
    0
    @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'
     
  6. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    Post the complete code if you want any help..
     
    tshuck likes this.
  7. metric_electric

    Thread Starter New Member

    Aug 21, 2013
    19
    0
    @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>
     
  8. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    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
    Code ( (Unknown Language)):
    1. <?php phpinfo(); ?>
    Does it report all the php information?
     
  9. metric_electric

    Thread Starter New Member

    Aug 21, 2013
    19
    0
    @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.
     
  10. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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...
     
  11. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    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.
     
  12. metric_electric

    Thread Starter New Member

    Aug 21, 2013
    19
    0
    @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
     
  13. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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
    Code ( (Unknown Language)):
    1.  
    2. error_reporting(E_ALL);
    3. ini_set('display_errors', 1);
    4.  
    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
     
  14. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Perhaps, you should post your directory structure too...
     
  15. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    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.
     
  16. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Hi.

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

    Code ( (Unknown Language)):
    1. <?php
    2. require('top.php');
    3. require('config.php');
    4. ?>
    I have the required files in parentheses and with '-sign.

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

    Thread Starter New Member

    Aug 21, 2013
    19
    0
    @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.
     
  18. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    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
     
  19. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Are you viewing your files via the web server or file explorer?
     
  20. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    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..
    Code ( (Unknown Language)):
    1. <html>
    2.  <head>
    3.   <title>PHP Test</title>
    4.  </head>
    5.  <body>
    6.  <?php echo '<p>Hello World</p>'; ?>
    7.  </body>
    8. </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: Jan 20, 2014
Loading...