Using PHP
Installing PHP
Unlike the other examples in Sections 1 and 2, the material in section 3 will not work unless it is published from a web server, either a personal web server set up on your local machine, or as a hosted online service. Details on how to set up the IIS webserver for Windows XP Professional can be found on the Install IIS page, and details for PHP set up can be found on the Install PHP page.
PHP Tags
PHP code always begins with <?php and end with ?> e.g.
<?php echo ‘hello world'; ?>
This is how PHP and HTML can be mixed together in your webpage.
PHP Statements
You tell PHP what to do by adding statements between the opening and closing tags. The above example had one statement, an echo statement which echoes the words ‘hello world' to the browser which displays them on the screen. Every statement ends with a semi-colon—don't forget it. Think of a PHP statement as a sentence with an instruction in it—e.g. “Print out the words ‘hello world' on the computer screen”.
Whitespace
Whitespace means characters such as spaces, carriage returns (newlines), and tabs which add extra space to your text. These are useful for making text clearer to read, but can cause PHP code to go wrong. The PHP interpreter ignores whitespace, so you can use tabs and other whitespace characters to layout your code without needing to worry about your code failing.
Comments
Comments in your code make it easier for someone else to understand, they don't do anything, they just provide explanations about what's going on in the code. e.g.
<?php echo ‘hello world';
// the echo statement prints characters on the screen
?>
As you can see, comments are denoted by two backslashes // at the beginning of the line. Make sure you put it at the beginning of each line you want to be a comment. To write a multi-line comment use the following format;
<?php echo ‘hello world';
/*
Code written by John Brown
Updated 12 Feb 2005
the echo statement prints characters on the screen
*/
?>
Now you know the basics, let's create a PHP page.
High Class Computer Supplies
We are going to create an orderform for a fictional computer supplyy company. The orderform will accept data, save it to a text file, and send a message of confirmation to the user, along with a list of items purchased and the total cost.
To see a demo of the form, click here;
To start the tutorial click on Dynamic Content.
