Whole document tree
    

Whole document tree

PHP HOW-TO: A Simple Example Next Previous Contents

7. A Simple Example

Suppose you have a form:

<FORM ACTION="/cgi-bin/php.cgi/~userid/display.html" METHOD=POST> 
<INPUT TYPE="text" name="name"> 
<INPUT TYPE="text" name="age"> 
<INPUT TYPE="submit"> 
<FORM> 
Your display.html file could then contain something like:
< ?echo "Hi $ name, you are $ age years old!<p>" >
It's that simple! PHP automatically creates a variable for each form input field in your form. You can then use these variables in the ACTION URL file.

The next step once you have figured out how to use variables is to start playing with some logical flow tags in your pages. For example, if you wanted to display different messages based on something the user inputs, you would use if/else logic. In our above example, we can display different things based on the age the user entered by changing our display.html to:

<?
    if($age>50);
        echo "Hi $name, you are ancient!<p>";
    elseif($age>30);
        echo "Hi $name, you are very old!<p>";
    else;
        echo "Hi $name.";
    endif;
>
PHP provides a very powerful scripting language which will do much more than what the above simple example demonstrates. See the section on the PHP Script Language for more information.

You can also use PHP to configure who is allowed to access your pages. This is done using a built-in configuration screen. With this you could for example specify that only people from certain domains would be allowed to see your pages, or you could create a rule which would password protect certain pages. See the Access Control section for more details.

PHP is also capable of receiving file uploads from any RFC-1867 compliant web browser. This feature lets people upload both text and binary files. With PHP's access control and logical functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded. See the File Upload section for more details.

PHP has support for the PostgreSQL database package. It supports embedded SQL queries in your .HTML files.

PHP also has support for the mysql database package. It supports embedded SQL queries in your .HTML files.


Next Previous Contents