Before you start
In this first part of the series you will learn about basic PHP syntax, forms and functions and how to connect to and use MySQL or any other database with your PHP application.
This tutorial walks you through building a simple workflow application with PHP. Users will register for an account, upload files for approval, and view and download approved files. Users designated as administrators can view uploaded files and approve them to make the files available to all users. Part 2 and Part 3 of this series explore HTTP password protection, XML, JSON, and other relevant issues.
This tutorial covers the following:
- Creating a basic page
- Variables, loops, and if-then statements
- Connecting to a database
- Using include files
If you're a programmer who wants to learn how to use PHP to build web-based applications, start here with Part 1 of a three-part series of tutorials. PHP is a script-based language that is easy to learn, but still enables you to build complex applications with robust functionality. This tutorial walks you through creating a basic PHP page using HTML forms. It also explains how to access a database.
This tutorial assumes you have no PHP experience. In fact, while it's useful for you to be familiar with the concepts of HTML, no other programming is necessary for this tutorial. Feel free to download the source code used in this tutorial.
You need to have a web server, PHP, and a database installed and available. If you have a hosting account, you can use it as long as the server has PHP V5 installed and has access to a MySQL database. Otherwise, download and install the following packages:
- Whether you're on Windows®, Linux®, or even Mac, the easiest way to get all of the necessary pieces of software for this tutorial is to install XAMPP, which includes a web server, PHP, and the MySQL database engine. If you choose to go this route, simply install, then run the control panel to start up the Apache and MySQL processes. You also have the option of installing the various pieces separately, but keep in mind you will then have to configure them to work together—a step which is already taken care of by XAMPP.
- Web server
- If you choose not to use XAMPP, you have several options for a web server. If you're using PHP 5.4 (as of this writing, XAMPP is only using PHP 5.3.8) you can use the built-in web server for testing. For production, however, I will going to assume that you're using the Apache Web server, version 2.x.
- PHP 5.x
- If you're not using XAMPP, you will need to download PHP 5.x separately. The standard distribution includes everything you're going to need for this tutorial. Feel free to download the binaries; you will not need the source for this tutorial (or ever, unless you want to hack on PHP itself). This tutorial was written and tested on PHP 5.3.8.
- Part of this project involves saving data to a database, so you'll need one of those, as well. Again, if you've installed XAMPP, you can skip this step, but if you choose to, you can install a database separately. In this tutorial, I'll concentrate on MySQL because it's so commonly used with PHP, so if you choose to go this route, you can download and install the Community Server.