January 01, 2002
One Wicked Site Admin Combo
April 28, 2000 Issue > Developers
PHP and MySQL: One Wicked Site Admin Combo
Effective adminstration of a Web site can ensure that site's success. Many developers are seeking technologies to achieve this success and make their jobs more streamlined. One way to do this is to use the powerful and popular combination of PHP and MySQL.
This tutorial will help you design and deploy a simple yet useful Web-based email administration application. Along with building a cool little app, we'll cover the following:
Let's begin by outlining the functionality we want to have within the application:
Before coding anything, let's turn our attention towards setting up the MySQL table that will hold subscriber information. This is easy, since there is really only one table to define (the one that holds the email addresses). I'll call it "newsletter_table."
mysql>create table newsletter_table ( email char(65); );
Easy enough! Now we're going to connect to the MySQL server and subsequently to the newsletter_table in order to perform queries. Instead of repeating these variables within each script, I like to put them in one central location, and use the
Why do I do this? The main reason is that it eliminates redundant code. Should you need to change a variable later, you would only need to make one modification. Less modification means less chance of an error. Also, if you want to add another variablesuch as a second tableonly one addition is needed.
Let's place these global variables into a file called init.inc, which you can check out in Listing 1. You can call this file whatever you want, but name it something that makes sense to you. After that, you'll need to make changes to the init.inc file so it connects to your MySQL server.
Okay! Now that the administrative part is out of the way, let's begin the fun stuffcoding.
The Importance of PHP Functions
User-defined functions provide several important services for the programmer:
We will develop user-defined functions to handle each of the services that our application will perform. I'm going to place all of these functions into a file titled "email_admin_funcs.inc". Check out the code in Listing 2. Here are some issues to be aware of.
Interface Intelligence
With the functions built, we now come to my personal favorite part of Web application developmentinterface design. I made this interface very generic, leaving room for you to add your own features or design as needed.
Figure 1 shows the simple interface I created. You can check out the basic code in Listing 3.
What's especially important about the interface is that it will act as a template. We'll be calling upon this file to execute all of the functionality of the application. The function called upon depends on the value of the $func variable passed along in the response.
Final Thoughts
Web administrators will want to extend this simple example. Here are couple of suggestions on where to go from here:
PHP provides users with the capability to develop useful applications quickly and with ease. As you can see from this exercise, you can create powerful tools in just a few short steps. Use some forethought about function usage and the general layout of the application, and you're that much closer to making your tasks much easier, and your site visitors much happier.
Jason is a Web/wireless application developer for Unstrung. If you add any cool functions to the above script, let him know!
Related Articles
|
|
|||||||||||||||||||||||||||||||
|
|
|
|