«^»
3.3. Using a form to supply data

Often the author of a WWW page will want to get data for his/her PHP script from the visitor. This can be done using a WWW form:

0026: <HTML><BODY>
0027: <FORM METHOD="POST" ACTION="helloform.php">
0028:    How many times? 
0029:    <INPUT TYPE="text" NAME="numrows">
0030:    <P>
0031:    <INPUT TYPE="submit" VALUE="submit">
0032: </FORM>
0033: </BODY></HTML>

This WWW form uses a text field to ask the visitor to the WWW page for the number of rows. When the visitor clicks on the submit button, the ACTION attribute of the WWW form indicates that the helloform.php script will be executed. Because the text field of the WWW form has the name numrows, the contents of this text field can be accessed in helloform.php by using this name as an index to PHP's $_POST array. Here is a PHP script that does this:

0034: <HTML><BODY>
0035: <?php
0036:    $numrows = $_POST["numrows"];
0037:    for ($rownum = 0; $rownum<$numrows; $rownum++)
0038:    {
0039: ?>
0040:       <P>hello world</P>
0041: <?php
0042:    }
0043: ?>
0044: </BODY></HTML>
Go to the WWW form at: http://www.dur.ac.uk/barry.cornelius/papers/phpintro/code/helloform.htm