Before developing forms, it is necessary to know about the two functions that helps us in collecting values through our forms. They are $_GET and $_POST. $_GET variable is used if the method of the form is set to GET
Information transfer in GET method occurs through the URL. Hence, its visible to everyone.Moreover, there is a limit to the maximum amount of data that can be sent.
Lets see a sample form for illustrating it clearly :-
<form action='action.php' method='GET'> Name: <input type='text' name='name'/> Age: <input type='text' name='age' /> <input type='submit' value='Submit'/> </form>
Suppose the user fills Dolly as name and 19 as her age and hit ENTER. This will take her to the file mentioned "action.php". It is this file where we are gonna use those submitted information and do whatever we wish. The URL in the above mentioned situation will be like this :-
action.php?name=Dolly&age=19 // variables start with a "?" and are joined by "&"
In order to access those values in action.php, we can simply use $_GET[variable name] and obtain the values.
$name = $_GET['name']; // $name = Dolly $age = $_GET['age']; // $age = 19
However, data transferred through the GET method is not secure as it is visible to everyone. Suppose you wanna login in your account and if the password is visible everytime you login, then its vunerable to hacking because it will also get stored in your browser history. So, we have another method for data transfer which is same as the GET, except, it is not visible in URL
POST function is used for transferring your values in case you use method = "POST" in the above mentioned form. Information sent through POSt method is invisible to others and has no limits on the maximum amount of data that can be sent. However, by default it is set to 8MB. It can be changed by increasing the limit in php.ini file of your server.
We can use the values sent in action.php in the following way :-
$name = $_POST['name']; // $name = Dolly $age = $_POST['age']; // $age = 19
One important point is that suppose the programmer of action.php and html form are different, then the person making the action.php file can still access both the values by using $_REQUEST array. It works equally good for both POST and GET variables.
$name = $_REQUEST['name']; // $name = Dolly $age = $_REQUEST['age']; // $age = 19 // works equally good in both the methods
To go to more details of action.php mentioned above, we need to know how to handle database MYSQL :-