Reputation: 369
I have this in my index.html file inside the body tag:
<?php
require('db.php');
$a = new db();
$connection = $a->connect();
$name = $connection->getName($connection);
echo $name;
?>
But what chrome gets is:
<!--?php
require_once('dbconnect.php');
require('db.php');
$abc = new db();
$connection = $abc--->
connect();
$names = $connection->getNames($connection);
echo $names;
?>
I use chrome and wamp. Do you have any idea what's wrong here?
Upvotes: 0
Views: 551
Reputation: 1420
Depending upon how your server is configured, you might not be able to call PHP from HTML. To solve this, make one of the changes below to your .HTACCESS file either in the root folder or the folder where the html page is running:
AddType application/x-httpd-php .html
That directive will enable php in all html pages. If you just want to add it for one particular page, use this directive:
<Files index.html>
AddType application/x-httpd-php .html
</Files>
The above assumes that your page is named index.html, which is what your sample code indicates.
Upvotes: 1
Reputation: 1680
Any document with the .html extension will be default be read without the php/cgi compiler. If you truly want to use PHP code in your pages you need to use the .php extension, or configure your Apache to open html pages with the php compiler.
Upvotes: 1
Reputation: 125
You have to rename your index.html file to index.php. If you haven't told your Apache server to treat .html files as .php files, your code just won't work.
Upvotes: 4