Want to learn how to use php to save data in forms. How come this doesn't work in a html file?


I'm a newbie please bear with me. I just finished learning how to create forms in html. Now, I want to learn how to save and display the data using php. While following along the php exercises in w3, I tried running this file but it didn't work when saved as a.html file. Could someone explain what I'm doing wrong and why the code text won't display? Thanks.

<!DOCTYPE html>

<h1>My first PHP page</h1>

 echo "Hello World!";




Your server is not setup to parse PHP in files with a .html extension. Add an .htaccess file to your web root with the following lines in it -

# allows HTML files to be interpretted as PHP files
AddType application/x-httpd-php .html



You should save it with a .php extension. I assume you're working locally and you would need to install PHP on your machine. The best way to install it locally is by using XAMPP or WAMP to emulate a server. I prefer using XAMPP https://www.apachefriends.org/index.html. Install it start the apache service, put this file in your htdocs folder i.e. 'root' and navigate to from the browser. This is a start, even if you put it on an "actual" server it'll work fine.




First off, you need to change your file extension from .html to .php

Are you running a web server? If not, you need to either be running a server like MAMP




just done you a quick form here

Copy and paste it to where ever you run you script,make sure it has a php extension, and see if it gives you the same result as it does in the link. If not then your configuration is wrong. If you have xampp then make sure it is in the HTDOCS directory

People are also looking for solutions to the problem: javascript - keep open submenu when new page


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.