Adelphia web hosting - 121Chapter 7Passing Information between PagesThe browser thus constructs
121Chapter 7Passing Information between PagesThe browser thus constructs the URL string: http://localhost/baseball.php?Team=Cubbies&Submit=SelectIt then forwards this URL into its own address space as a new request. The PHP script towhich the preceding form is submitted (baseball.php) will grab the GETvariables from theend of the request string, stuff them into the $_GETsuperglobal array (explained in amoment), and do something useful with them in this case, plug one of two values into atext string. Strictly speaking, the name-value pairs in a GETquery are not part of the HTTP or addressingstandards. In one of the odd footnotes of Internet history, the W3C allowed for the possibil- ity of extra data to be passed to a resource after a ?in the URI string but never specified pre- cisely what form that data should take. Usage quickly established the notion of name-valuepairs separated by ampersands, but this is not part of any W3C standard. The following code sample shows the PHP form handler for the preceding HTML form:
Go, !
Note that the value inputted into the previous page s HTML form field named Team is nowavailable in a PHP variable called $_GET[ Team ]. Finally, you should see a page that saysGo,Cubbies!in big type. At this point, it makes some sense to explain just how to access values submitted from pageto page. This chapter discusses the two main methods for passing values: GETand POST(there are others, but they are not covered until Part III). Each method has an associatedsuperglobal array, explained in more depth in Chapter 9, which can be distinguished fromother arrays by the underscore that begins its name. Each item submitted via the GETmethod is accessed in the handler via the $_GETarray; each item submitted via the POSTmethod is accessed in the handler via the $_POSTarray. The syntax for referencing an itemin a superglobal array is simple and 100 percent consistent: $_ARRAY_NAME[ index_name ] where the index_nameis the name part of a name-value pair (for the GETmethod), or thename of an HTML form field (for the POSTmethod). As in the preceding example, $_GET[ Team ]indicates the value of the form select field called Team , sent by the GEToperation in the original file. You must use the array appropriate to the method used to send data. In this case, $_POST[ Team ]is undefined because no data was POSTed by theoriginal form. NoteTip09If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.