I have a set of PHP scripts running in HTML files for a project. There is a main window with tabs and each tab calls one of these HTML-inclusive-of-PHP files. For this purpose, I am using iframes. The PHP scripts connect to a MySQL database to retrieve data and display as required by the user. I am using WAMP for this purpose and have set a HTML page as the index file. However, if I give a HTML page as the index file, the tabs do not respond. As in, I can see the tab but it doesn't connect to the database and doesn't retrieve data. If I save the same file without any changes as a PHP index file instead, I cannot see the frames and tabs anymore, but the PHP script works and data is retrieved effortlessly from the database. I tried this with every one of my tabs and every time, the PHP script works while the HTML including the PHP doesn't. What am I doing wrong ? How do I make the HTML page with the PHP work ?
2 Answers
The way to execute PHP on a .html page is to modify your .htaccess file. This file may be hidden, so depending upon your FTP program you may have to modify some settings to see it. Then you just need to add this line for .html:
AddType application/x-httpd-php .html`
Or for .htm
AddType application/x-httpd-php .htm`
If you only plan on including the PHP on one page, it is better to setup this way:
<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>
This code will only make the PHP executable on the yourpage.html file, and not on all of your html pages.
or in httpd.conf if you want it globally
3 Comments
Left click on the Wamp icon in the bottom right tray of your computer >> Apache >> left click on httpd.conf >> scroll 2/3rd's the way down >> add AddType application/x-httpd-php .html to as shown below >> save and close it >> restart Wamp >> Done!
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .html