7 January 2008
You'll need to know how to set up a dynamic site in Dreamweaver and also have PHP and MySQL set up on your development system. You'll also need to understand how to restore a SQL file to a MySQL database.
Meetings, conventions, and conferences are an important part of almost every profession. In recent years, attendee registration has moved to the Web. In this article you'll learn how to create a multipurpose catalog page that displays the different seminars for each day of the event. You'll also learn how to create a basic event registration application in PHP using a basic Dreamweaver server behavior. This application consists of three pages:
Before you begin building the application, examine the database tables that are employed and also verify that the database connection is properly set up in Dreamweaver.
Note: It's a good idea to have your dynamic PHP site already set up at this point and have unpacked the sample files into the local root folder.
The database that accompanies this article is a relatively simple one with three tables: presentations, registrants, and admin. Only the first two tables come into play during this exercise; the admin table is used in conjunction with a related article that describes how to set up an administrative site for event registration.
The presentations table maintains information for the various sessions held during the event. The presentations table includes data columns for storing the presentation's name, a short description and a longer description (see Figure 1). There are also columns for the date and time of the talk, its duration and the day of the event (1, 2, 3, and so on) on which the presentation is given. Speaker details, such as name and file name for a picture, round out the table schema.
In comparison, the registrants table has far fewer data columns. Only columns for the registrant's first name, last name, e-mail address, and event name are included. You could—and probably would—require a much more robust set of data columns for an actual application, but this structure should give you a good sense of the type of information you can gather.
The SQL file for the Subscriptions database is included in the sample files download, in the database folder. You can recreate it on your test server through any number of utilities including phpMyAdmin, MySQL Control Center, or MySQL Administrator.
After you've established your database, it's time to create a connection to it in Dreamweaver. To do so, follow these steps:
With your PHP dynamic site, MySQL database, and Dreamweaver connection all established, you're ready to build the first page of the application.
To help your registrants decide which days of your event to attend, you'll want to display the session details. This information is stored in the presentations table of the database and can be called up dynamically. In this exercise, you'll create the necessary recordset, insert the dynamic data, and set up links to display what's happening on the various days.
The first task is to add the recordset to the page. This recordset pulls data from the presentations table and is filtered to include only the sessions on a single day. A URL parameter is used to create the filter.
The presentations.php page has a few placeholders already set up to help guide you. Before you can take advantage of them, you'll need to create a recordset.
For your own application, you can, of course, limit the data columns to just those used.
Although you've completed the Simple view of the recordset (see Figure 3), you're not quite done. To make sure that the first day's events are displayed when the page loads initially, you'll need to change the default value of the URL parameter in the Advanced Recordset interface.
Now that the recordset is ready to go, you're all set to bind the dynamic data to the page.
Inserting the dynamic data to the page is pretty straightforward and made even simpler with the placeholder elements to show you the way. The only tricky part is formatting the date and time properly; to accomplish this, you'll need to add a bit of hand coding to the page.
This action allows the page to indicate which day of the event is currently being displayed.
Next, set up the proper date and time formatting. As I mentioned, this will require a bit of hand-coding.
<?php echo date("l, F j, Y, g:i a", strtotime($row_rsPresentations['PresentDate'])); ?>
Dreamweaver does not provide a binding panel format for date and time with PHP, so you have to add it yourself. There are two functions applied to the recordset row:
strtotime(). The innermost function,
strtotime(), converts the string stored in the database to a time format that PHP can manipulate. The
date() function handles the formatting. At runtime, these single letter formatting codes will result in output like this: Saturday, March 1, 2008, 9:00 am. For more information about date and time formatting, see the PHP online manual.
Here, each link is set to the current page with a different value for the URL parameter PresentDay, which, you'll recall, was used to filter the recordset.
The core of the dynamic information is all in place (see Figure 8).
Next, you'll make sure you get all the data you need.
At this point, the page would display a single record. For the final phase, you'll add a Repeat Region server behavior to display all the records in the recordset.
When you select the data to be repeated, you generally want to make sure to include a bit of space after the day so that each record will be given its proper weight. You could, of course, enclose everything in a
<div> tag and handle the separation through CSS.
Naturally, you can add as many days to your event listing as needed. Next, you'll create the registration page.
The registration page makes the most of the Dreamweaver Insert Record server behavior. A simple form is used to gather the needed information.
The register.php page already has the form and primary form elements in place. If you select any of the existing form elements, you'll notice that they are named the same as the corresponding data columns in the registrants table. There's even a hidden form element called RegEvent with the value for this event, Realty Conference. The key action now is to add the Insert Record server behavior.
Because all the form elements have the same name as the data columns in the registrants table, Dreamweaver automatically makes the assignments (see Figure 11).
Dreamweaver writes out the server side code indicating the entire form is now dynamic (see Figure 12) and you're good to go!
The confirm_registration page is a simple "thank you" page that informs the registrant that his information has been received. Your basic event registration application is now complete.
There are a good many things you could do to build upon this event registration application:
Tutorials and samples