php Lessons

You have found this page because you were either looking to learn php to modify some script or to write your own. Over the series of these pages, I will give you sample code and try to explain what the commands that you are entering tells the machine to do.

If you live in the Jackson, AL area and are interested in taking classes, visit to send me a note to let me know. I am considering offering training at one or more local libraries depending on if there are enough people interested in learning.

Anyway, for part 1, I am going to start out by explaining a little about php or personal home page. It is one of the most common languages for web programming, works 100% with html and allows you to build a website that can be 100% database driven with only a few files. php works with MySQL, the open source database solution.

php contains a series of complex commands but is pure logic. Knowing that and remembering that, you can easily start looking at code and figuring out what it is saying and modify the code in such a manner to perform the operation that you are wishing to perform.

That being said, let’s start lesson 1 with a simple script (No, not the hello world or foo bar script) but one where you will learn a couple of commands. If you don’t already have Xampp installed, you can download it here. Once downloaded, install it to your machine and run the control panel. Turn on MySQL and apache.

You will also need to download a php editor. I recommend tsWebEditor, it is free and open source. I code 100% of everything using this software. You can download it here.

For Windows users, open C:->xampp->htdocs-> and create a new folder. You can name it php Lessons because we will continue to write our code in this folder until we have a completely functional MySQL driven site but for now, it will start as a simple script.

With tsWebEditor, open a new file. We will start off by saving this file in as index.php in C:->xampp->htdocs->New folder just created.

In order to execute a php function, you must tell the file that the input code is php. You do this by opening the statement like this: <?php

I always go ahead and press enter twice to close the php statement so that it is never forgotten. This can sometimes make a difference when entering html in between php statements.

At this point, your code should look something like this:


In between these php tags, let’s get some code in there. With php, you can comment out single lines or multiple lines by adding // or /*. If you comment out a single line it is notated as // and multiple is /* but always must be followed by */ or it will continue to comment out and will not execute. So, we are going to enter in a little bit of comments and commands to let us know what the commands do.

Being said, on line 2, enter the following code:

echo "Welcome to your very first php script.
"; //The echo command tells php to print or call back the information in quotation marks. Also note the use of the html linebreak command. We are able to enter html into php statements whenever we print or whenever we echo.
echo "This is my very first simple executable script! YAY!!!! We did it"; //This is what our browser will show us next. Note that we didn't use any html tags on this line. We will edit this later.

Now when we run this in our browser, it should appear just like this:
We to your very first php script.
This is my first simple executable script! YAY!!!! We did it

In the next lesson we are going to cover more actions such as forms and posting data from one page to a secondary page.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.