Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Exploring this array will reveal all the environment variables as well as a few other
variables. Similar to GLOBALS are HTTP_GET_VARS, HTTP_POST_VARS, and
HTTP_COOKIE_VARS. As their names suggest, these are associative arrays of the variables
created by the three methods the browser may use to send information to the server.


The combination of Web server and operating system will define the set of environment
variables. You can always write a script to dump the GLOBALS array to see which are
available to you. Alternatively, you can simply view the output of the phpinfo function.


Listing 7.2 Viewing Environment Variables


<?
/*
* make a multiplication table
/


// start table
print("<TABLE BORDER=\"1\">\n");


for($Row=1; $Row=12; $Row++)
{
//start row
print("\n");


//do each column
for($Column=1; $Column <= 12; $Column++)
{
print("");
print($Row * $Column);
print("");
}


//end row
print("\n");
}


//end table
print("\n");
?>


Getting Input from Forms


Sending text to the browser is easy to understand. Getting input from forms is a little
tricky. HTML offers several ways to get information from the user via forms. There are
text fields, text areas, selection lists, and radio buttons among others. Each of these
becomes a string of text offered to the Web server when the user clicks the submit button.


When a form is submitted, PHP turns each form field into a variable. The variables
created this way are like any other variable. You may even change their values. They are
created as if you had written the PHP code to put values into the variables. This means
that if you put two form variables on a page with the same name, the second one may

Free download pdf