user13354649
user13354649

Reputation:

Difference between an HTML and a PHP file

I have to query a mysql database using php, but a file with the .html extension for example my index.html does not recognize the <?php ?>.

Now I have index.php, what are the differences between this and the index.html file? I can work properly with the index.php file or there is a method to insert <?php //SOME CODE TO MY DB ?> this type of code into an .html file?

P.S. I know that ajax exists, but in all the tutorials I have seen the file extension was .php and not .html and I can't understand how to use it.

Upvotes: 0

Views: 50

Answers (2)

Ythaenagor
Ythaenagor

Reputation: 21

You have to open the php file through an apache (or other php-handling) server. For instance, if you use XAMPP, and have index.php in the XAMPP directory, you would open a browser and go to localhost/index.php. The server then converts it into html, which a browser can handle.

Upvotes: 0

Quentin
Quentin

Reputation: 944565

They are both text files with code in them.

The difference isn't in the files, but in how your webserver treats them.

It is configured to run files with a .php extension though a PHP engine, and to serve up .html files directly.

Upvotes: 1

Related Questions