13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

694 Chapter 30 Building a Mailing List Manager<br />

The mail table contains information about each email message that is sent through<br />

the system. It stores a unique ID (mailid), the address the mail is sent from (email), the<br />

subject line of the email (subject), <strong>and</strong> the listid of the list it has been sent to or will<br />

be sent to.The actual text or HTML of the message could be a large file, so you need to<br />

store the archive of the actual messages outside the database.You also track some general<br />

status information: whether the message has been sent (status), when it was sent (sent),<br />

<strong>and</strong> a timestamp to show when this record was last modified (modified).<br />

Finally, you use the images table to track any images associated with HTML messages.<br />

Again, these images can be large, so you store them outside the database for efficiency.You<br />

need to keep track of the mailid they are associated with, the path to the<br />

location where the image is actually stored, <strong>and</strong> the MIME type of the image<br />

(mimetype)—for example, image/gif.<br />

The SQL shown in Listing 30.1 also sets up a user for <strong>PHP</strong> to connect as <strong>and</strong> an<br />

administrative user for the system.<br />

Defining the Script Architecture<br />

As in the preceding project, this project uses an event-driven approach.The backbone of<br />

the application is in the file index.php.This script has the following four main segments:<br />

1. Perform preprocessing. Do any processing that must be done before headers can be<br />

sent.<br />

2. Set up <strong>and</strong> send headers. Create <strong>and</strong> send the start of the HTML page.<br />

3. Perform an action. Respond to the event that has been passed in. As in the preceding<br />

example, the event is contained in the $action variable.<br />

4. Send footers.<br />

Almost all the application’s processing is done in this file.The application also uses the<br />

function libraries listed in Table 30.1, as mentioned previously.<br />

The full listing of the index.php script is shown in Listing 30.2.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!