The GET method is simply a way of passing data to a server. In this tutorial we will help you to get familiar with retrieving data (which was sent via HTML forms) using PHP.
When data is sent using an HTML form to the server, PHP will intercept this data and create an array which holds all the data.
When the GET method is used to send the data, PHP will store the data in the superglobal $_GET associative array. If we want to retrieve the data, we would have to retrieve it from the array as described in our PHP array tutorial.
Retrieving some data passed using the GET method is fairly simple.:
$variable = $_GET['parameter'];
That's all there is to retrieving data passed to a script using the get method.
Suppose this form was sent:
<html> <body> <form action="http://www.example.com/index.php" method="get"> Name: <input type="text" name="name" /> School: <input type="text" name="school" /> <input type="submit" /> </form> </body> </html>
The URL it would go to is:
If we had a script at that location we would be able to retrieve the values using:
<?php $name = $_GET['name']; $school = $_GET['school']; ?>
Once we had the variables we would be able to work on them as we desired.