There are a number of ways to incorporate user input into your scripts. The single most used method of taking in user input is by using HTML forms. Let's take a very simple example of a HTML file with forms which point to a PHP script. I'm aware that some of you might not exactly be comfortable with HTML, if that's the case please read a few tutorials on the net about HTML.
<form action="http://www.website.com/script.php" method="post">
Form 1: <input type="text" name="form1"><BR>
Form 2: <input type="text" name="form2"><BR>
<input type="submit" value="submit">
The "get" method means that the form data is to be encoded by the browser into the URL and sent to the specific program. The "post" method means that the form data is to appear within a form data set and sent to the script. There is a general rule which states that you should use the "get" method when retrieving information and use the "post" method when sending information.
Let's say we filled in the above forms, filling in "form1" with "hi" and filling in "form2" with "bye". If were were to submit the above form with the "post" method, we would see "http://www.website.com/script.php
" in the address bar. The information of the forms would be sent with the form data set (don't mind this too much, read more about it at http://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set
). But if we were to submit the information via the "get" method, you would see your address bar change to this: "http://www.website.com/script.php?forms1=hi&forms2=bye
". The form information is encoded right inside the URL where you can see it instead of being hidden like the "post" method. Everything after the question mark ("?") is known as the query string. The query string holds all the user input someone submits via a form (or just manually in the URL). Every different form is separated by an ampersand ("&") or semicolon (";") and form names and values are separated by the equal sign ("=").
Now you might ask why this is important. Well first of all, URL caching. "get" methods are cached while "post" methods aren't cached by your browser. According to http://support.microsoft.com/default.aspx?scid=kb;EN-US;q208427
, the "get" has a limit on the amount of information you can send by it. Because the "get" method uses the URL to send user input, it is limited by the maximum length a URL can be (2048 characters). The "post" method has no limitations on the amount of information you can send by it.
Because I don't want to get into the HTML of PHP scripting too much, I'm going to use the "get" method more often. This is because, I can show you examples without directly using HTML.
For example, we can access a URL like "http://www.website.com/script.php?forms1=hi&forms2=bye&forms3=something
" and right from that we can get into the PHP of "script.php". Hope that made sense, next few lessons I'll go into detail with this stuff.