In PHP there is a large amount of variables that are predefined and ready to be utilized in your scripts if needed. A couple examples of these predefined variables are the _POST and _GET arrays. These arrays are used a lot when handling data submitted through forms.
If you have some experience with HTML forms, you know that there are two methods of submitting the data collected by forms. There is the POST method, which silently submits the data to the server, and there is the GET method, which submits the data through the URL and is visible in the address bar of your browser.
The global variable used to access the data depends on which method you use in the form. Let's look at an example, suppose you have the form below and you are using the POST method to submit it.
<form action="process.php" method="POST">
|
|
Once the user clicks submit, all of the data from the form inputs will be available to the script specified in the action attribute. (in this case process.php)
To access this data, all you need to do is use the global variable (POST or GET) like you would a normal associative array. Here is a simple example of what could be used for process.php.
<?php
|
|
Notice that we use the name of the input tag to access it in the _POST/_GET array, so if you had an input named 'message', you'd access it like this: $_POST['message'] or $_GET['message']... depeding on which action you chose.
Hopefully this tutorial gave you a better idea how to access form data. If you have any questions, please use the discuss link below.
| Discuss Tutorial: Accessing Form Data | 7 Comments |

