PHP 4 Windows
Learn And Run PHP On Your Windows Computer

This PHP 4 Windows Tutorial examines several simple programming errors. Remember after completing Step 3 of the PHP download tutorial you can copy the contents of the EasyPHP directory to another Windows computer and run these and future PHP programs if you have an Internet browser, even if you don't have a live Internet connection.

Simple PHP Programming Errors

This tutorial starts from the program created in Step 7 and executed in Step 8 of the PHP Download Tutorial. For your convenience we repeat these steps below.


Step 1 Create the hello2.php PHP program as shown in Figure 1.

Simple PHP errors tutorial figure 1

Simple PHP Errors Tutorial Figure 1
Source code for PHP program containing HTML tags.



Step 2 Run the hello2.php program created in Step 1. The results are shown in Figure 2.

Simple PHP errors tutorial figure 2

Simple PHP Errors Tutorial Figure 2
Output for PHP program containing HTML tags.



Step 3 Let's start by removing the semicolon ; after the first echo statement in the hello2.php program. Save the modified program with the name hello3.php that corresponds to the Step number. The results are shown in Figure 3.

Simple PHP errors tutorial figure 3

Simple PHP Errors Tutorial Figure 3
PHP program missing a semicolon.



Step 4 Run the program as usual. Note that the error message includes a line number that may be confusing. When our programs get bigger we will introduce a PHP program editor that can help you detect PHP errors more easily. The results are shown in Figure 4.

Simple PHP errors tutorial figure 4

Simple PHP Errors Tutorial Figure 4
Error results for a PHP program missing a semicolon.




Step 5 Open the hello2.php PHP program and this time remove the semicolon ; after the second echo statement. Don't be sloppy when testing; if your program contains unexpected errors your testing results can be misleading to say the least. Save the modified program the name hello5.php as shown in Figure 5.

Simple PHP errors tutorial figure 5

Simple PHP Errors Tutorial Figure 5
PHP program missing a different semicolon.



Step 6 Run the hello5.php program. As you will see, there are no errors. The semicolon immediately preceding the ?> is not necessary. Many people still code it. That way if you include a third echo statement you won't need to modify your second echo statement. Why ask for trouble? The results are shown in Figure 6.

Simple PHP errors tutorial figure 6

Simple PHP Errors Tutorial Figure 6
PHP still says hello while "missing" a semicolon.



Step 7 Open the hello2.php PHP program and this time remove the tag containing ?php and the one containing ?. We are no longer specifying that we are using PHP. Save the modified program the name hello7.php as shown in Figure 7.

Simple PHP errors tutorial figure 7

Simple PHP Errors Tutorial Figure 7
Is this a PHP program?



Step 8 Run the hello7.php program. As you will see, the word echo shows up twice as do the semicolons. Believe me, making this mistake in a more complicated PHP program could generate more serious errors. The results are shown in Figure 8.

Simple PHP errors tutorial figure 8

Simple PHP Errors Tutorial Figure 8
It's not a good PHP program.



Step 9 Open the hello2.php PHP program and this time make an HTML error before saving the modified program with the name hello9.php as shown in Figure 9.

Simple PHP errors tutorial figure 9

Simple PHP Errors Tutorial Figure 9
Forgetting an HTML tag.



Step 10 Run the hello9.php program. The messed-up results are shown in Figure 10.

Simple PHP errors tutorial figure 10

Simple PHP Errors Tutorial Figure 10
Results of a missing HTML tag.





Exercises. 1) Try removing a single quotation mark.
2)Try removing the tag containing the php.
3) Try removing the body tag.
Keep a record of all your tests. Don't forget to repair a previous error before introducing a new error.