PHP Tutorial – 14 – User Input
When an HTML form is submitted to a PHP page the data becomes available to that script.
<form action="MyPage.php" method="post"> <input type="text" name="myString" /> <input type="submit" /> </form>
Sending with post
If the form is sent using the post method the data can be accessed through the $_POST array. The names of the fields will be the keys in the array. Data sent with the post method is not visible on the URL of the page, but this method has the drawback that the state of the page cannot be saved, for example if the page is bookmarked.
echo $_POST['myString'];
Sending with get
The alternative to post is to send the form data with the get method and to retrieve it using the $_GET array. The variables are then displayed in the address bar, which effectively holds the state of the page.
echo $_GET['myString'];
Because the data is contained in the address bar this means that variables can not only be passed through HTML forms, but also through HTML links. The $_GET array can then be used to change the state of the page accordingly. This gives an easy way of passing arguments from one page to another.
<a href="MyPage.php?myString=Hello+World">link</a>
Request array
If it doesn’t matter whether the post or get method was used to send the data the $_REQUEST array can be used. This array contains the $_GET, $_POST, and $_COOKIE arrays all in one.
echo $_REQUEST['myString'];
If you like this tutorial please +1 it:


![[Affiliate link] Total Training]( http://d3qzmfcxsyv953.cloudfront.net/images/pvt-affiliates/totaltraining.png)
![[Affiliate link] Lynda](http://d3qzmfcxsyv953.cloudfront.net/images/pvt-affiliates/lynda.png)

