Archive for May, 2008

2. Enter the transaction page by entering (Free web host) the

Thursday, May 22nd, 2008

2. Enter the transaction page by entering the following code in your PHP editor and saving it as user_transact.php: Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

$result = mysql_query($sql) or die( Invalid query: . (Com web hosting)

Wednesday, May 21st, 2008

$result = mysql_query($sql) or die( Invalid query: . mysql_error()); if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); $email = $row[ email ]; } else { $email = ; } } else { $email = ; } ?>

Email Address:
/>

If you aren t currently a member, please provide your name:

First Name:

Last Name:

Select the mailing lists you want to receive:

498 Chapter 14
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Web hosting account - Of course, some day your site will be

Tuesday, May 6th, 2008

Of course, some day your site will be extremely popular, and you might have thousands of e-mails to send. At that point, it might be time to start looking at a professional mailing list management application. That, however, is beyond the scope of this book. After the page is done with its transactions, redirect the user to the admin.php page. Most of the time, this happens so quickly that you don t notice the redirection at all. header( Location: admin.php ); Sign Me Up! Now it s time to look at the other half of the application, the Mailing List Signup form. This is the page you send your users to that enables them to sign up for any of the mailing lists that you have created. This application consists of user.php, user_transact.php, thanks.php, and remove.php. As always, you ll also be using the config.php file that you already created. On the surface, when you view the page from the Web, it looks like a simple application. However, there s a lot going on inside. So let s open it up and see what s under the hood! Try It Out Mailing List Signup The first page you are going to create is the actual signup form. 1. Enter the following code in your favorite PHP editor and save it as user.php:

Sign up for Mailing List:

Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Web server - If anyone was subscribed to that mailing list,

Monday, May 5th, 2008

If anyone was subscribed to that mailing list, you must delete those subscriptions, too: $sql = DELETE FROM ml_subscriptions . WHERE ml_id= . $_POST[ ml_id ]; mysql_query($sql) or die( Could not delete mailing list subscriptions. . mysql_error()); break; When you send a message, you want to let the user know which mailing list you are referring to. If the mailing list ID (ml_id) is all instead of a number, you will want to reflect that as well: case Send Message : if (isset($_POST[ msg ], $_POST[ ml_id ])) { if (is_numeric($_POST[ ml_id ])) { $sql = SELECT listname FROM ml_lists . WHERE ml_id= . $_POST[ ml_id ] . ; $result = mysql_query($sql, $conn) or die(mysql_error()); $row = mysql_fetch_array($result); $listname = $row[ listname ]; } else { $listname = Master ; } What follows is a more complicated SQL statement than you ve written thus far, but not too difficult. What s happening here is that you are grabbing the e-mails, first names, and user IDs from the ml_users table where the mailing list ID (ml_id) matches their user ID in the ml_subscriptions table. You do this by using the INNER JOIN command in SQL. You also must not send any e-mails or newsletters to those that are awaiting subscription confirmation, so select only those where pending = 0, or false. If pending = 1 (true), then that row is ignored. $sql = SELECT DISTINCT usr.email, usr.firstname, usr.user_id . FROM ml_users usr . INNER JOIN ml_subscriptions mls . ON usr.user_id = mls.user_id . WHERE mls.pending=0 ; If the administrator did not choose all in the select list, you must limit your selection to the specific users that are subscribed to the mailing list the administrator selected. You do this by tacking on the AND condition: if ($_POST[ ml_id ] != all ) { $sql .= AND mls.ml_id= . $_POST[ ml_id ]; } Now execute the previous SQL statement, and return the results: $result = mysql_query($sql) or die( Could not get list of email addresses. . mysql_error()); 495 Mailing Lists
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

This is the link to the e-mail (Web hosting servers) portion

Sunday, May 4th, 2008

This is the link to the e-mail portion of the admin s functions, which is pretty self-explanatory: Send a quick message to users You should be able to figure out quickmsg.php fairly easily. Most of it is HTML, and the PHP code is practically identical to the code used to build the select in admin.php. Feel free to cannibalize your own code as often as you need. If you are scratching your head and trying to remember exactly how class.SimpleMail.php works, now would be a good time to take a break and go check out Chapter 11. There s an analysis of the script toward the end of the chapter. Finally, you come to the real workhorse of the Mailing List Administrator application, admin_ transact.php. This page is the one to which you post your forms, and it will process that information, update the database tables, and send out e-mails as required. Let s take a look under the hood: require( config.php ); require( class.SimpleMail.php ); Remember seeing the preceding line in admin.php? Having your connection data in one file and including it in each page makes your code much more efficient. The same applies to the SimpleMail include. Of course, you already knew that. Let s move on to create the connection to the database, and select it so that you can work with it: $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die( Could not connect to MySQL database. . mysql_error()); mysql_select_db(SQL_DB, $conn); Did the user click an action button? if (isset($_POST[ action ])) { Depending on which button was clicked, you re going to perform one of three actions: create a new mailing list, delete an old mailing list, or send a message to the users subscribing to a mailing list: switch ($_POST[ action ]) { Not only must you delete the mailing list, like this: case Add New Mailing List : $sql = INSERT INTO ml_lists (listname) . VALUES ( . $_POST[ listname ] . ) ; mysql_query($sql) or die( Could not add mailing list. . mysql_error()); break; case Delete Mailing List : $sql = DELETE FROM ml_lists WHERE ml_id= . $_POST[ ml_id ]; mysql_query($sql) or die( Could not delete mailing list. . mysql_error()); 494 Chapter 14
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

My web site - How It Works Let s take a look at

Saturday, May 3rd, 2008

How It Works Let s take a look at admin.php: require( config.php ); Now you should see why you put the connection values in a separate file. By doing this, all you need is a single line to include the constants, and you can use them in this page. Let s pause here for a moment and talk about form submittal. A common practice is to post a form back to itself, and you certainly could have done that here. When your page contains data that needs to be inserted into a database, however, you need to think twice about a self-posting form. If the user were to refresh or reload the page, all of your database functions would run again, and that could be disastrous. You would end up with duplicate data, or delete records you didn t mean to delete. Obviously, you don t want anything like that to happen, so to minimize the probability, you post to a separate form called admin_transact.php. This page handles all of the necessary database transactions, and then redirects back to the page from which you came. If the user reloads the page at that point, no harm will come to your database.
You might notice that all of your buttons have the same name, action, each with a different value. When posting the form, you will be accessing the $_POST[ action ] variable to see which button was pressed, and perform the appropriate actions. This allows you to use one script for multiple transactions, rather than having to create a page with multiple forms, each posting to a different transaction page. Now you get all of the mailing lists available and wrap them in option tags so that they will appear on your page in a drop-down select box.

493 Mailing Lists
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Figure 14-1 Figure 14-2 (Web server address) 492 Chapter 14

Friday, May 2nd, 2008

Figure 14-1 Figure 14-2 492 Chapter 14
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

$ft .= following URL:n ; $ft .= http:// . (Web hosting services)

Thursday, May 1st, 2008

$ft .= following URL:n ; $ft .= http:// . $_SERVER[ HTTP_HOST ] . dirname($_SERVER[ PHP_SELF ]) . /remove.php?u= . $row[ user_id ] . &ml= . $_POST[ ml_id ]; } else { $ft = You are receiving this email because you subscribed ; $ft .= to one or moren mailing lists. Visit the following ; $ft .= URL to change your subscriptions:n ; $ft .= http:// . $_SERVER[ HTTP_HOST ] . dirname($_SERVER[ PHP_SELF ]) . /user.php?u= . $row[ user_id ]; } $msg = stripslashes($_POST[ msg ]) . nn ; $msg .= ————–n ; $msg .= $ft; $email = new SimpleMail(); $email->send($row[ email ], stripslashes($_POST[ subject ]), $msg, $headers) or die( Could not send email. ); } } break; } } header( Location: admin.php ); ?> That s it for now. You still have the user functions to worry about, but you ll tackle those in a bit. For now, load a few of these pages in your browser to see them in action; then we ll figure out how they work. 5. The first page of the mailing list application you want to take a look at is the Mailing List Administrator page. Load admin.php in your browser. As you can see in Figure 14-1, you can create a new mailing list, delete an existing mailing list, or send a quick message to users. Feel free to create a couple of new mailing lists. Go crazy, have fun, get wacky. Good. Let s move on. 6. Click the link at the bottom of the Mailing List Administrator page, Send a quick message to users. A new page appears where you can compose a new message and send it to either a single mailing list, or all users (see Figure 14-2). If you just created these pages, you don t have any users yet. You can compose a message, but it won t go to anyone. You ll need to create the user pages first, which you ll do shortly. 491 Mailing Lists
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.