In this lesson we will link an HTML form with a PHP Script.
Our HTML form, has two inputs.
Both inputs have a name attribute. The first input's name attribute is set to fname. The second is set to email.
Our form action is set to send.php, using the POST method.
If you are following along with this tutorial, you will need to create a file called send.php and save it in the same directory as your html form page.
Remember we are saving these files in the folder called phplessons.
In the send.php file, we have a First Name and Email text label. Next to each label we have an echo statement that outputs the information the user filled into the form.
First Name: <?php echo $_POST["fname"]; ?><br>
Email: <?php echo $_POST["email"]; ?>
To do this we use an echo statement with the superglobal POST variable that contains the information typed into each input.
Now let's test everything. Open the webpage containing the form in your browser using the localhost URL. Mine is called forms.php.
Now type some information into the inputs and click submit.
You should see the data outputted on the send.php page.
You will notice that the transmission of the data from the form to the php file was invisible to the user.
Let's change our send method to GET, and also update the superglobal variable $_POST to $_GET.
Now refresh your forms.php page, plugin some info and press submit.
You will notice the output is the same, but take a look at the URL. You can see the variables and the values all in plain sight.