Menu:

Sponsor

Discover Master of Alchemy, our first iPad/iPhone and iPod touch game!

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


Flash/PHP guestbook

1. Introduction

1.1 What are we going to do.

Hello to everyone! Here we are again with my second lesson . Last time we talked about how to make a simple news ticker using interaction beetween Flash and a PHP server-side script based on a MySQL database.

This time, the tools we are going to use are the same again, but the goal we want to achieve is different: we will analyze how I built my IWE Guestbook. The level of this lesson is more advanced than my first one, so the target of this tutorial are experienced developers, expecially under Flash MX, as there is a huge work to do.
So, you have to know how to work with functions, how to organize your work in several files, how to use shared libraries and how to use the LoadVars object and its methods. But you also must know how databases work, SQL and basic PHP 4 syntax. To speed up our work and avoid a too big "jump" into the OOP world I made a large use of Components for this application. You can find them into the Sources archive (IWE_GB_SOURCES.zip). Before opening the source files you must read carefully the REAME_FIRST.txt file, as there are important license terms and conditions to know. Well, if you accepted all terms and conditions go on reading, else stop here.

You can download the IWEDataManager and the FadingCoverTextbox components also on my website in the Downloads section (the FadingCoverTextbox is available also on Macromedia Flash Exchange and on Flashcomponents.com).

Ok, it looks like you agree to all the license terms and conditions, so let's continue our lesson, or better, let's begin :-)

Well, the first thing to think of is what is the result that we want to reach: I thought about a quite complex but easy to use and upgrade application, not a guestbook for this tutorial, but a guestbook for daily usage, for the webmaster that needs a guestbook but that maybe does not know Flash or for a developer like me, that maybe wants to give a quality product without losing time when the customer asks him for a guestbook. So this product must be totally dynamic, totally customizable, with administration facilities and easy and quick to install. So my project is about a software that has all these requirements and that every one (me at first place) can make it run in minutes or maybe seconds. I don't want to list here all the installation procedure, as it is well explained in the README_FIRST.txt file. We will touch all steps, but from the developer side and not from the user one.

2. THE SERVER-SIDE WORK

2.1 Projecting the structure of the application and the database.

What is a guestbook?
It's an area where an user can leave a message to the author or the owner of a website. So, which parts do we need to make this kind of application? Well, a basic guestbook should have a page (or movie in this case) that shows all entries saved by the site's visitors and an entry insertion form to let new visitors save their own entry.
All these data need to be stored in a database, so we need also a table that's used to save these information.
In IWE Guestbook I had others tasks to manage: the first thing I thought about was the installation procedure. The user has got to unzip the guestbook archive file and launch the installation user interface. With this procedure the software must create all tables that are needed and save the settings information inside one of them as each administrator can customize the guestbook interface. So the first step to do is to create the PHP script that will receive data from the Flash form and will create the database structure and save the settings inside the settings table. We could do this part also without a Flash form, but as one of my goals was to let the user to have a preview of the settings he is going to set, I preferred to achieve it by using Flash. Before showing the code of the first PHP script let's think about the data we want to store in the settings table:

  • the administrator username
  • the administrator password (those data are saved for future administrator logins)
  • the header color
  • the rows background colors
  • the header text color
  • the body font color
  • the welcome text
  • the header text
  • a custom logo

The above data are the fields of our table, with a field that was not listed and that is optional, as this table will have only one record: the ID field. I insert it too as it is useful for updating the settings in a second time and because to "normalize" a database the first rule is that all tables must own at least a primary key.

Note: Refer to http://www.alessandroperrone.com for guestbook updates

 

2.2 Setting the configuration file

Well done, let's introduce two scripts before showing the PHP installation script.
I want this guestbook an easy-to-install software. As we are not wizards, we need to know four data for making a connection to the MySQL server: the hostname, the database name and the username and password. These are the only data that the user will edit by his own opening a file. I called this file "config.php". Let's look at its code:

            
<?php
/********************************
ALL CODE © alessandroPERRONE.com
read the LICENSE AGREEMENT in
README_FIRST.txt file
********************************/

// change the following values with your own MYSQL server access data
$host "hostname or IP address";
$user "userID";
$pwd "password";
$db "your database name";
?>

The above code is well explained.

Note: Why are we making a separate file to store these information?

There are several factors to look at: the user work must be easy, we cannot make him open all .php files to change the connection info. Maybe the user is not a developer at all so he must be able to configure the connection data even without having any coding basis. This from the users side. From the developer side it's a question of workflow optimization and time saving for future updates. It's easier to change information only once and it's less difficult to require a single file in each file respect to write the same lines of code each time. This is the concept that is at the base of this application building process. I will use it with both the server-side and the client-side code.