Home

About

Contact

PHP and MySQL
for Absolute Beginners

You can buy the Have Fun With PHP and MySQL Quick Start Workbook from the following Amazon sites:

download Have Fun With PHP and MySQL Quick Start Workbook from amazon.com Amazon.com download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.co.uk Amazon.co.uk
download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.ca Amazon.ca download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.de Amazon.de
download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.in Amazon.in downloadPHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.fr Amazon.fr
downloadPHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.es Amazon.es download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.it Amazon.it
download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.nl Amazon.nl download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.co.jp Amazon.co.jp
download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.com.br Amazon.com.br download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.com.mx Amazon.com.mx
download PHP and MySQL for Absolute Beginners Quick Start Workbook from amazon.com.au Amazon.com.au

PHP and MySQL

PHP is a server-side scripting language and MySQL is a database system. Together, they provide programmers with the tools to develop powerful database-driven websites and applications.

The Quick Start Workbook

The workbook assumes that you, the reader, have a basic knowledge of HTML and CSS, and have perhaps developed (hand-coded) one or two sites for yourself. The structure of the book is as follows:

  • Introduction to PHP programming
  • Setting up a PHP and MySQL development and test environment
  • Developing sample applications
  • Working with MySQL at the command prompt

The workbook is written using a conversational, easy-to-follow, approach, with the aim of getting you writing PHP scripts as quickly as possible. Although there is a certain amount of theory contained in the book, the objective is to learn by doing rather than by reading through huge amounts of text.

Note: If you want to download the various applications that are used in the book, you need to access this website from a PC to make the download links available.

PHP and MySQL for Absolute Beginners Quick Start Workbook

Download the Sample Code

Use the following link to download all the sample code used in the book. You will need to enter a username and password, which you can get from the last page in the quick start workbook itself. If you have any problems downloading the files, please contact us and we will try to help.

Click Here to Download the Sample Code for the Book

Once you've downloaded the zip file, unzip it (anywhere) and then copy the whole unzipped file structure to your web root. Then, using your favorite web browser, navigate to the various sample applications and websites to open them.

Here's a very short introduction to PHP

PHP (a recursive acronym for PHP: Hypertext Preprocessor) is a computer scripting language, originally designed for producing dynamic web pages. It is used primarily for server-side scripting, but can also be used from a command line interface or in standalone graphical applications.

PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It generally runs on a web server, taking PHP code as its input and creating HTML web pages as output. It can be deployed on most web servers and on almost every operating system and platform free of charge. PHP is installed on more than 100 million web servers. It is also the most popular Apache module among computers using Apache as a web server.

... and one for MySQL

MySQL is the world's most popular open source relational database management system (RDBMS). It runs as a server providing multi-user access to a number of databases.

MySQL is popular for web applications and acts as the database component of the LAMP, BAMP, MAMP, and WAMP platforms (Linux/BSD/Mac/Windows-Apache-MySQL-PHP/Perl/Python), and for open-source bug tracking tools like Bugzilla. Its popularity for use with web applications is closely tied to the popularity of PHP, which is often combined with MySQL. PHP and MySQL are essential components for running popular content management systems such as Drupal, Joomla, and WordPress.

The Quick Start Workbook

This Quick Start Workbook is aimed at novice web developers who want to know how to use PHP and MySQL to develop dynamic, database-driven, websites and applications.

The book is written using a friendly, conversational, approach, with the aim of getting you developing websites and applications as quickly as possible. Although there is of course a certain amount of theory contained in the book, the objective is to learn by doing rather than by reading through chapter after chapter of reference material.

What's in the Book?

The book starts by providing a PHP crash course, covering the essential building blocks that are necessary in order to begin the development of dynamic, database-driven websites and applications. The book describes how to set up a development and test environment before examining various sample sites. A more detailed breakdown of the chapters is given below.

Chapter 1 - Getting Started with PHP

This chapter introduces the basics of PHP web development, covering topics such as PHP syntax, the use of variables and arrays, PHP sessions, using cookies to keeping track of user activity, using HTML forms and validating user input, looping through code based on whether a condition is true or false, and functional versus object-oriented programming.

This chapter provides you with the basic PHP building blocks that will enable you to develop scripts and complete websites and applications that actually do something useful, which is the purpose of later chapters in the book.

Chapter 2 - Setting Up a PHP and MySQL Development Environment

Having got to grips with the essentials of PHP programming, this chapter shows you how to set up an environment suitable for developing and testing PHP and MySQL dynamic websites and applications.

Chapter 3 - Setting Up PHP and MySQL Websites and Applications on a Web Server

This chapter explains how to download and install the sample sites and applications that are located on this Quick Start Workbook website. The chapter then goes on to explain how to run dynamic sites and applications from the web root, and how to set up and work with MySQL databases.

Chapter 4 - Developing a Compound Interest Calculator
Compound Interest Calculator

The first sample application we develop in the workbook is a compound interest calculator.

What is a compound interest calculator? When you deposit money in a savings account, it earns interest (hopefully). If you leave the earned interest in the savings account along with the original deposit, then the interest itself also earns interest. This is known as compounding and is how this calculator works.

The calculator itself is a simple PHP application, which does not require the use of MySQL.

Although the calculator is currency-independent, to make things interesting we pretend that we're using the Bitcoin currency. However, changing it to use US Dollars would be a simple case of removing the Bitcoin image and replacing it with a '$' sign ... simple !

Chapter 5 - Developing a Loan Calculator

This chapter shows how to develop a loan calculator, which lets you calculate any one of four values:

Loan Calculator

By knowing three of these values, you can calculate the fourth.

Following on from the Bitcoin theme established in the previous chapter, the loan calculator uses Bitcoin as the pretend currency. The calculator also only requires PHP to perform the calculations - there's still no need for MySQL, but that all changes in the next chapter.

This chapter also contains a bonus application that shows how JavaScript can be used to create a calculator whereby the results are updated instantly without the need to click a 'show results' button.

Chapter 6 - Adding a Hit Counter to a Web Page

The web page hit counter provides us with our database-driven web application.

... and here it is - in all its glory !

9888

Simply press the F5 key a few times to increment the counter.

Although web page hit counters have long since fallen out of favor with website developers (they were popular in the late 1990s and early 2000s), producing one does provide us with an easy introduction to how PHP and MySQL can be used together to produce dynamic web content.

Chapter 7 - Creating an Online Poll (or Survey)

In this chapter we create an online poll (or survey) that you can insert into a web page to gather visitors' views on a particular subject. For our poll, we ask visitors to select their favorite programming language(s) from a list of options. The results are then displayed both numerically and graphically. You can see a working version of the poll on the home page of this site.

We look at two versions of the poll: one whereby visitors can keep going back and making new selections, and one in which a cookie is used to only allow visitors to make one set of selections.

The online poll provides us with our second PHP and MySQL web application, and is a more complex example than the one we looked at in Chapter 6. Adapting the application for a different poll would be pretty straightforward and would be a useful follow-up exercise to carry out.

Chapter 8 - Creating a Simple Email Form Handler / Feedback Form

On your website you may decide that you want to allow visitors to register with you so that they can receive a newsletter, or perhaps you want to provide a feedback form on your site. Either of these two options is easily possible by creating a form and then emailing the form data to a specified email address.

Registration and Authentication - Create a Members Only Website

The form we provide in this chapter can be easily customized by adding new fields applicable to your particular needs.

Chapter 9 - Creating a Members-Only Website

In this chapter we develop a complete user registration and authentication system that can be used to create a members-only area on a website.

This is a common requirement of many sites, whereby there are certain pages that are available to all visitors (public pages), while other pages are only available to users who have registered (members-only pages).

Chapter 10 - Troubleshooting Tips

When developing websites and applications - especially when you're creating dynamic sites using server-side scripting and databases - things don't always go to plan. In this chapter we identify potential problems that might prevent a website or application from working, and examine how to resolve them.

Appendix - Working with MySQL at the Command Line

In the appendix we look at some MySQL commands that may prove to be useful during the development of dynamic, database-driven websites and applications. It is often convenient to have a Command Prompt window open while developing and testing PHP scripts. You can then enter MySQL commands at the command prompt to check that the database tables are being updated correctly by the scripts.