PHP Basic Tutorial
MySQL Connection
Form handling in PHP involves processing data submitted through HTML forms. This process typically includes gathering user input, validating and sanitizing the input, and then using the data (e.g., storing it in a database, sending an email, or generating output).
PHP allows you to handle form data submitted through both the GET
and POST
methods.
Create a simple HTML form for user input:
Try it yourself
The $_SERVER['PHP_SELF']
variable is a PHP superglobal that contains the current script's file path. It is often used in forms to set the action
attribute, allowing the form to submit to the same script for processing. Here's an explanation of its use, particularly in the context of the POST method.
Try it yourself
When action=""
, the form submits to the same page that displays the form.
Feature |
GET |
POST |
---|---|---|
Data Location |
Appended to URL as query parameters |
Sent in the request body |
Visibility |
Visible in the URL |
Hidden from the URL |
Security |
Less secure (data in URL) |
More secure (data hidden) |
Data Length |
Limited (based on URL length) |
Virtually unlimited |
Caching |
Can be cached by browsers |
Cannot be cached |
Use Cases |
Non-sensitive data, search queries |
Sensitive data, large data submissions |