Question

I'm familiar with HTML but only just starting to learn php. I can't seem to figure out why this code isn't working. I've previously had no problems with include()'s but that is when the php code is it's own distinct file. This time around I'm trying to create a dynamic web page with php scripts. I have apache running with xampp and I have the gf.css file and testing.php in the same folder as the main html file.

The problem I can't seem to figure out is that nothing is showing up in the text box when I try and run the HTML page. It seems as though nothing in the php tags is running. I put in echo statements to try and determine what the problem was but nothing showed up unless, however, I placed a h1 tag after the first " in my echo statement. But inn this case, no matter where I placed the closing h1 tag, the rest of the php script just printed. It was as if I couldn't close the tag.

That's as much info as I can give really. Any help and/or explanations as to what I'm doing wrong would be much appreciated! Thanks in advance.

Here's the HTML file

<html>
    <head>
        <link rel='stylesheet' type='text/css' href='gf.css'>
        <body>
            <h1>This is my web page</h1>
            <div id='main_box'>
                <?php           
                    include ('testing.php');                 
                ?>
            </div>
        </body>
    </head>
</html>

Here's the .css file

#main_box
{
    height:500px;
    width:400px;
    color:white;
    background-color:1e1e1e;
}

And here's the testing.php file if that matters

<?php

    echo "test page";

?>
Was it helpful?

Solution

If you want to write php code then file extension must be ".php". So change your main HTML file extension to PHP.

OTHER TIPS

First Solution:

If you want to write php code then file extension must be ".php". So change your main HTML file extension to PHP.

Second Solution:

You can tell Apache to treat .html files as PHP by adding a new FilesMatch directive:

1. Open C:/xampp/apache/conf/extra/httpd-xampp.conf
2. Search: 
   <FilesMatch "\.php$">
   SetHandler application/x-httpd-php
   </FilesMatch>
3. Add those three line:
   <FilesMatch "\.html$">
   SetHandler application/x-httpd-php
   </FilesMatch>

Third Solution:

You can do it by adding an .htaccess file into your document root that contains:

AddHandler application/x-httpd-php .html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top