Try It Out Mailing List Administration Next, you (Web site domain)

April 26th, 2008

Try It Out Mailing List Administration Next, you will create the admin page, where the administrator (that s you!) can create, delete, and rename mailing lists. 1. Create the following code, and save it as admin.php:

Add Mailing List:

Delete Mailing List:

Send a quick message to users

486 Chapter 14
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

This SQL is used to create the tables (Geocities web hosting)

April 25th, 2008

This SQL is used to create the tables in your database: $sql1 = <<Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

How It Works (Personal web server) Your first file, config.php, contains

April 25th, 2008

How It Works Your first file, config.php, contains just five lines: define( SQL_HOST , localhost ); define( SQL_USER , bp5am ); define( SQL_PASS , bp5ampass ); define( SQL_DB , comicsite ); define( ADMIN_EMAIL , your@emailaddress.com ); These constants are created separately so that in the event that you make a change such as moving the application to another server, or changing the password, it can be done in only one location. If this data were in each file, any change would require modification of several files. Include config.php in each file that requires access to MySQL like so: require( config.php ); You use require() instead of include() because if the file is not loaded, you want to halt loading of the page. Another option would be to use include(), and then immediately test for the existence of one of the constants. If it does not exist, you could then redirect the user to another page, which makes for a more user-friendly experience. As you can see here, the constants from config.php are used to make your connection: $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die( Could not connect to MySQL database. . mysql_error()); $sql = CREATE DATABASE IF NOT EXISTS . SQL_DB; $res = mysql_query($sql) or die(mysql_error()); mysql_select_db(SQL_DB, $conn); Take notice of the CREATE DATABASE statement. There are a couple of things you should be aware of about creating databases. If you already have a database (one that you created in another chapter, or if your site is already using a database), it s better to keep your mailing list tables in that database. You don t need extra databases because if your Web site spans multiple databases, you will need to create multiple connections to those databases, and that is extra overhead that is just not necessary. In addition, if there are any relationships between your tables from this application and tables from other apps, they need to be in the same database. For example, if you have a user table that stores your registered users for all applications, all of the applications that rely on that user table should reside in the same database. If you do need to create a new database, the CREATE DATABASE command may still not work if your site is hosted by an Internet service provider (ISP). Some ISPs don t allow programmed creation of databases. If this is the case, you may need to go through your ISP to create the database (through PHPMyAdmin, for example) and run sql.php. Just be sure to put the proper database name in the code. See Chapter 10 for more information about creating databases. 484 Chapter 14
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Christian web host - 3. Now you re going to create the tables.

April 24th, 2008

3. Now you re going to create the tables. You can create them with your MySQL tool (such as PHPMyAdmin), or you can simply enter the following code, save it as sql.php on your server, and load it in your browser: 4. If you ran sql.php in your browser, it should display a Done. message, indicating the database tables were created. 483 Mailing Lists
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Yahoo free web hosting - . Web site notifications: These are important tidbits

April 23rd, 2008

. Web site notifications: These are important tidbits of information about your Web site. You will want to let your users know you ve improved the level of security for online transactions on your site, for example. . Newsletters: If you had a family Web site, for example, and wanted to let your whole family know about the new addition to your family, you could send them a newsletter. . Important announcements: Our site will be down for 5 days. Sorry for the inconvenience. We ll let you know when it is back up. (Oooh . . . an opportunity for two mailings!) . Advertising: Perhaps you ve partnered with an online comic book store to offer deals on rare comics to your members. Once you know what you want to say, you format the information you wish to share, using plain text or HTML. You try to figure out how you are going to e-mail this information to every member of your Web site. If you can figure out how to send it, you hope that your users will be able to read and appreciate what you sent with their many types of e-mail clients. In this chapter s project, you are going to send out two different e-mails: Web site change notifications and a newsletter. The former will be sent to all members of the Web site. The latter will be sent to those who subscribe to the newsletter only. You are going to use HTML in your mass e-mail, of course. Because Chapter 11 taught you how to send HTML in an e-mail, this should pose no problem at all. You can also e-mail links to an online version of the HTML you are sending, so that those with text e-mail clients can see your hard work, as well. Coding the Administration Application The first thing you re going to do is to create the administration page, where you can add and remove mailing lists. There are a few scripts to tackle, but because they all rely on each other to work, you need to enter them all now. Hey . . . you re the one who wanted to write some code. Let s get cracking! Try It Out Preparing the Database First, you re going to create the file that will hold the server, username, password, and database values. 1. Open your favorite text editor, and enter the following code, making sure you use the proper values for your server: 2. Save the file as config.php. 482 Chapter 14
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

14 Mailing Lists Ah, yes. Mailing Lists. Two (Adelphia web hosting)

April 22nd, 2008

14 Mailing Lists Ah, yes. Mailing Lists. Two simple, innocent words that never meant anyone any harm. That is, until a few years ago, when someone decided to put the two together, and junk mail was born. Oh sure, mailing lists are used for more than junk mail. After all, how else are you going to receive your Quilting Monthly magazine unless your name and address are on a list? What does this have to do with PHP? In the world of e-mail and your incredible new Web site, a mailing list is a perfect way for you to communicate with all of your users. You might need to let every user know that your site has moved to a new address. Maybe you want to send out a monthly newsletter. Whatever the reason, you will occasionally need to send e-mails to many people, and you will need a relatively easy way to do so. Specifically, this chapter discusses the following: . Administering a mailing list . Creating a mailing list . Spam . Opt-in and opt-out So, are you ready to learn how to spam your Web site users? We hope not, because that is not what you are going to do. Yes, you are going to use mailing lists. And yes, you are going to send out mass e-mails. However, you are going to be responsible, and send e-mails only to those people who have agreed to be recipients. Right? Let s get started. What Do You Want to Send Today? Before you actually create the mailing list, you must have something that you intend to send to your recipients. The train of thought usually goes like this: You decide that you have some information you want to share with your users. Here are a few possibilities:
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Web design rates - Summary Well, if you didn t have writer s cramp

April 21st, 2008

Summary Well, if you didn t have writer s cramp before, you probably do now. We hope this application has given you some insight into the separation of content and design. Because of the way the application was designed, you can easily modify the look and feel of the application by either directly altering your header and footer files, or using a CSS file to set up different styles. This won t matter to your users; they will still be able to enter articles without ever having to worry about what the article will look like on the Web when it s published. We also hope that you understand the importance of updating your site often enough to draw users back again and again. By adding an application like this to your site, and allowing users to add content for you, you create a dynamically changing site with fresh information. Just think about all the ways you could implement such a design: . Create a message board. (This is examined in more detail in Chapter 16.) . Add a daily comic. Perhaps you have an artist who can draw you a comic every day. You could create an application that allows him or her to upload comic strips and allows users to comment on them. . Compile photo journals. A while back, there was a project in which photographers went all over the world, and in a 24-hour period, they took their pictures and uploaded the digital images, and people in the central office typed up descriptions and allowed people to view them online. It was a very ambitious project and a perfect example of a CMS application. The bottom line is that if you have content that you want to be able to update on a regular basis, you definitely want to implement a CMS application. And now, you have the basic tools to build one on your own! Perhaps you should send your users an e-mail to tell them of your improved functionality. You ll do that in Chapter 14. Exercises After all that typing, are we so cruel that we d include more work at the end? Yes. Yes we are. See how you might accomplish the following tasks: 1. Delete when appropriate. When reviewing an article, the delete button always shows up, regardless of what happens in the transaction page. Alter the code so the Delete button only shows up when the article is pending. 2. Find out about the author. Authors of articles might want the readers to know a little more about them. Add the ability to enter extra fields in a user s profile, and provide a link on the article full-view page to the author s information. 3. Notify the author. Authors might want to be automatically notified when their stories have been approved. Add an e-mail notification upon approval, and give the user the ability to toggle their notification on and off. 479 Building a Content Management System
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

outputStory($row[ article_id ], TRUE); } } require_once footer.php ; ?> 2. (Photoshop web design)

April 20th, 2008

outputStory($row[ article_id ], TRUE); } } require_once footer.php ; ?> 2. On any page with a search box on the top, enter a word that existed in the article you created. Once you submit the form, search.php will appear, and any matches should be shown. How It Works First, you include the necessary files:

Search Results

n ; if ($result and !mysql_num_rows($result)) { echo

No articles found that match the search terms.

n ; Otherwise, loop through the results and display them as snippets on the screen: } else { while ($row = mysql_fetch_array($result)) { outputStory($row[ article_id ], TRUE); } } require_once footer.php ; ?> 478 Chapter 13
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Web page design - if (mysql_num_rows($result) == 0) { echo No

April 16th, 2008

if (mysql_num_rows($result) == 0) { echo No published articles available ; } else { while ($row = mysql_fetch_array($result)) { echo
n ; echo . htmlspecialchars($row[ title ]) . (published . date( F j, Y ,strtotime($row[ date_published ])) . )

n ; echo

n ; } } Then load the footer. It is only a few lines of HTML for now, but some day you will want to put a menu, or perhaps a copyright line. The great thing is, even if your site uses 300 pages, you will have to add that information in only one place: footer.php. ?>

Try It Out Search The final thing you are going to add is a simple search feature. Using the power of the full-text searching in MySQL, you can easily put a keyword search field on each page, and show the results here. 1. Create search.php:

Search Results

n ; if ($result and !mysql_num_rows($result)) { echo

No articles found that match the search terms.

n ; } else { while ($row = mysql_fetch_array($result)) { 477 Building a Content Management System
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Pending Articles This code gets all pending articles

April 15th, 2008

Pending Articles

This code gets all pending articles written by this user. They are ordered by date_submitted, with the oldest being first. Please note that if there are no pending articles, this will not return a MySQL error. You will still get a result set, but there won t be any rows. You handle that contingency next. No pending articles available ; } else { You loop through each pending article and display the title (with a link to the article), along with the date/time it was submitted. while ($row = mysql_fetch_array($result)) { echo
n ; echo

n ; echo

n ; } } Okay, this next code is almost identical to the code used to display pending articles. This time, display them using the date_published column. We recommend high quality webhost to host and run your jsp application: christian web host services.


. htmlspecialchars($row[ title ]) . (submitted . date( F j, Y , strtotime($row[ date_submitted ])) . )