Let's start by looking at that form again from the previous tutorial on using GET, except there is one small change in the method parameter:
Code :
Output:
Although there is only a minor change to the code the URL looks very different:
Output:http://www.yourdomainhere.com/postform.php
There are no visible parameters and the page keeps the data secure and not publicly visible. Below is the code for retrieving the data and display it, you'll notice it's very similar to the GET function:
Code :"; echo "Your pet's age is " . $petAge; ?>
If you entered "dennis" and "10" the output would be:
Output:Your pet's name is dennis Your pet's age is 10
So when should the POST function be used? Mainly when handling data that is private, such as passwords. It shouldn't be used when wanting to allow users to bookmark a page as it will not work correctly. You can see a working example of the form by clicking here. In the next tutorial we will look at validating data submitted from a form!
To post comments you must sign in to your account below!
If you do not currently have an account click here to create one now!