Fetch the data from a HTML form with PHP
To fetch the data from a HTML form, we have to use the “$_POST” variable.
Here is an example:
I created a HTML file named: input.html which has a HTML form in it:
<html> <form name="form1" method="post" action="test.php"> <input type="text" name="textfield1" /> <input type="submit" name="Submit" value="submit"> </form> </html>
The HTML form has 1 text field and 1 submit button, and what we want to do is to fetch the input of the text field with a PHP file. The form shows that when we click the submit button, it will direct us to a PHP file called “test.php”.
In the file test.php:
First thing we have to do is to fetch the input from input.html, we use “$_POST” variable to do so.
<?php $temp=$_POST["textfield1"]; echo $temp; ?>
$_POST["textfield1"] is a variable which holds the data fetches from textfield1.
$temp is a variable which created to store the data of $_POST["textfield1"], this is just to make it easier to read with a short variable.
At last, we echo it to see if the fetching process is working or not.





