PHP Form Handling

PHP

The '$_GET' Method

This function gets the object which was added into the URL:

By typing the given URL example, which is right here, this makes the system activate, because you are including the word "query" in the URL. After the "query=" text, you can write any word after it and it will be displayed in the "echo" statement.

The '$_POST' Method

This function is used alot in forms, where the code fetches the details after a form submission:

If you get an error that "username is undefined", then don't worry, because that's a typical behaviour of PHP. After submitting the form, you should see your typed username echoed under the form.

The '$_REQUEST' Method

This is used when not sure what method exactly will be used on a form. Also not recommended on :

The '$_SERVER["REQUEST_METHOD"]' is used to check whatever the method is coming from a form - is it get or post. We also use some santizing to prevent XSS and SQL attacks - you might want to look up what these are.

Full Example of A Secure Form

This is a form, where an user would submit their details for whatever reason:

It could be useful for an email sending system or some sort of a registration.