HTML Form Handling in PHP
You’re ready to start handling forms in PHP!
<?=is shorthand for
- PHP provides superglobals which can be accessed anywhere in the script.
$_GETis an associative array containing data from a GET request.
$_POSTis an associative array containing data from a POST request.
$_REQUESTis an associative array containing data from both GET and POST requests. It should only be used if you don’t care which method was used.
- The array keys in the PHP request superglobals are set by the
nameattributes in the HTML form, which need to be unique.
actionattribute is used to specify which file should handle data from the form request.
This code contains two forms:
- A form using the GET method, which is submitted and handled by handle_get.php.
- A form using the POST method, which is submitted back to the same file (no
Use these forms to check your understanding of how PHP handles the form inputs.