First Steps in PHP – A Beginner’s Tutorial


So you’ve decided to make the move into dynamic languages. Congrats and welcome to the club (you’ll teach you the secret handshake later)!

PHP is a great choice: it’s easy to learn, cheap to learn, and very popular.

What Is PHP?

PHP is a dynamic coding language. If you’re like me, that didn’t help me at all when I started learning it, so let’s break it down.

Dynamic: HTML (which I’m assuming you know already…if you don’t, you want to start there) is Static. You type code and it obeys. A Dynamic language can do so much more; it can connect to databases of information, customize pages depending on the person, and handle complicated math problems.

Think of it this way; HTML is a Lemming (ie. Drone, no thought) and PHP is an employee (ie. it obeys, but it can also accept input and solve problems).

How Do I Start?

Well, here is a good place! But seriously, you’ll need three things to start:

1) A way to write code. Whatever you currently use for HTML should work fine. Personally, I use Dreamweaver, but I’ve also heard sublimeText2 is an awesome program. You can also just use notepad (though I wouldn’t recommend it).

2) A way to view code. Basically, you really need a hosting account online. If you REALLY don’t want to spend money on it, you can install PHP on your Localhost. However, in my opinion, this is a study in wasted time – 15 hours later, I still couldn’t get mine to work right.

3) All pages we add PHP coding to, must be saved with a file extension: .php instead of the normal .html/.htm. This allows the computer to know what’s going on. Don’t worry, you can still use HTML on those pages.

How to Think

If you’ve never programmed in a dynamic language before, how to think will become a huge issue in the beginning. Every problem you want to solve in PHP, you’ll need to break down into the smallest possible issue and solve it in steps.

So if I were telling PHP to display something from a database, here’s what I would do:

1) Connect PHP to the database

2) Tell it what table to get information from (databases can have multiple tables – like multiple spreadsheets)

3) Take all the information and put it in a variable

4) Tell it to write that variable on the page.

And that’s just to display something!

Whenever the problem seems insurmountable, break it into Baby Steps and suddenly, you’ll know what to do next.