Retrieving Form Data Using the GET Method in PHP
Let's look at an example. Let the file
form.php contain a form that is submitted
using the GET method to the page result.php:
<form action="/en/result.php" method="GET">
<input name="test1">
<input name="test2">
<input type="submit">
</form>
If we enter some data into our form in the browser and
press the button, the form will be submitted
to the page result.php:
<?php
var_dump($_GET); // array with keys test1 and test2
var_dump($_POST); // empty array
var_dump($_REQUEST); // array with keys test1 and test2
?>
You can also display the contents of a specific input:
<?php
echo $_GET['test1'];
?>
You can also take the contents of both the first and the second inputs, combine them into a string, and display it:
<?php
echo $_GET['test1'] . $_GET['test2'];
?>
Create a form with three inputs. Let numbers be entered into these inputs. After submitting the form, display the sum of these numbers.