The POST method is a very common and used method in PHP. It allows people to send information to the server and use this information.
Where do we find this sort ? Everywhere ! When you login on a website it is probably trough a POST method, when you are going to comment a topic/blog it would be trough a POST method!
So how do we use it ?
Easily ! I have made an example right here.
To make it a bit more easier to understand what happens I will explain it to you.
The first thing the script will do is to check if someone has pressed the submit button. (You can always let the isset() function check if something exists like a $_GET or a $_POST or $_SESSION,...). If the user has clicked on the submit button he will check if he has putted some data into the input with name="name"! (!empty means not empty).
When both things are valid he will continue executing the script into the { } (read If/elseif/else structure). In here I have scripted it so that the user will see his input (like his name).
So when I would use this script I would see :
You pressed on the submit button !
Your name is: Tom
But how does the script know my name is Tom ? Because it read out $_POST['name'] what data their was putted in and now outputs it again !
Ok, this would happen if both things were valid, but what would happen if they weren't ? Then the script would show you a form with 2 things
an inputbox and a submit button.
As you can see the name of the submit button & inputbox are the same as the name between $_POST[' ']. Thanks to this the $_POST will know what he must search for !
Any questions ? Post them here.