|
| HOW TO PASS DATA AND VALUES BETWEEN PAGES WITH THE POST METHOD $_POST IN PHP
Dynamic websites have the ability to pass data from one page to another. PHP provides such ability using a variety of methods, one of which is to post data using forms.
Suppose you have the following form on your site:
<form action="process.php" method="post">
<input type="text" name="username">
<input type="submit" value="Submit">
</form>
Let's break down the form over a few lines to explain further:
<form action="process.php" method="post">
The action="process.php" part tells the form which page to post the form to when the submit button is pressed.
The method="post" part specifies that the form data must be transferred to the process.php page using the post method.
<input type="text" name="username">
Now this is a very important part. This line displays a text input field. Assume a user types in the work jackal and clicks the submit button. A variable $_POST['username'] is automatically created and it's value will be equal to the user's input which was jackal. If you echo $_POST['username'] in the process.php page, you will get jackal outputted. Note that the variable $_POST['username'] get's it's name from the name of the input text field which is username. Another example:
<input type="text" name="email">
The post variable name created will be $_POST['email'] because the name of the input text field is email.
<input type="submit" value="Submit">
This simply displays a submit button.
Note that when the submit button is pressed, the page process.php is opened. Check your browser's address and you will notice that there are no variable strings after process.php. This is why the post method is considered more secure than the get method. The post method hides the variable strings whilst the get method does not.
 |
|
|