0

let this be sample.php

<?php
    $con=mysql_connect("localhost","root","");
    mysql_select_db("final_year_sample",$con);
    $qt=mysql_query("select * from gd_graph");
    header("Content-Type:image/jpg");
    $x_gap=40;
    $x_max=$x_gap*13;
    $y_max=250;
    $im = ImageCreate($x_max, $y_max) or die ("Cannot Initialize new GD image stream");
    $background_color = ImageColorAllocate($im, 234, 234, 234);
    $text_color = ImageColorAllocate($im, 233, 14, 91);
    $graph_color = ImageColorAllocate($im,25,25,250);
    $x1=0;
    $y1=0;
    $first_one="yes";
    while($nt = mysql_fetch_array($qt)){
        $x2=$x1+$x_gap;
        $y2=$y_max-$nt['sales'];

        ImageString($im,2,$x2,$y2,$nt['month'],$graph_color); 
        if($first_one=="no"){
            imageline($im,$x1, $y1,$x2,$y2,$text_color);
        }
        $x1=$x2;
        $y1=$y2;
        $first_one="no";
    }
    ImageJPEG($im);
?>

the above sample.php code works well and gives the output as output generated from above code

What i wish to do is:

I want to include the sample.php in the below HTML page

    <html>
    <head>
        <title>Front page</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="container">
            <span id="title">Prototype for vehicle Routing problem Solution</span>
            <div style="display:none;" id="graph_space">
                <?php
                    include('sample.php');
                ?>
            </div>
        </div>
    </body>
</html>

but i get the following error,

Error displayed when i try to include the sample.php in

JRodDynamite
  • 12,325
  • 5
  • 43
  • 63
  • Possible duplicate of [How do I add PHP code/file to HTML(.html) files?](http://stackoverflow.com/questions/11312316/how-do-i-add-php-code-file-to-html-html-files) – Newton Sheesha Mar 08 '16 at 07:04

2 Answers2

0

You cannot include PHP files in an html file that way as html file won't recognize <?php ?> tags

Though you can try do this Create a .htaccess file in directory and add this code to .htaccess file

AddHandler x-httpd-php .html .htm

or

AddType application/x-httpd-php .html .htm

It will force Apache server to parse HTML or HTM files as PHP Script

Newton Sheesha
  • 1,245
  • 1
  • 8
  • 13
0

You have to declare the file a .php page with 'HTML within it'. Change: page.html > page.php

And then your include will run, it can't run on a static HTML page. Think about it, yo.

Dr Upvote
  • 8,023
  • 24
  • 91
  • 204