If the (Kids web site) e-mail address was found in the
If the e-mail address was found in the database, you simply grab the user ID from the record that was returned. Either way, you now have a $user_id. You also have a mailing list id, retrieved from $_POST[ ml_id ]. That s all you need to create a subscription record. } else { $row = mysql_fetch_array($result); $user_id = $row[ user_id ]; } You may recall that the ml_subscriptions table contains three columns: user_id, ml_id, and pending. The first two values you have. The last one, pending, should be set to 1 until the user confirms the subscription. You initially set up the table to set pending to 1 as a default, so that column is automatically taken care of. So you now have all the data you need to create a subscription, and just like that, you insert the appropriate data into the subscriptions table. $sql = INSERT INTO ml_subscriptions (user_id,ml_id) . VALUES ( . $user_id . , . $_POST[ ml_id ] . ) ; mysql_query($sql, $conn); Now all that is left to do is to notify the user. You do this in two ways: with a Thank You Web page that confirms that the subscription was processed, and with an e-mail to request confirmation because you don t want people to be able to sign other people up for mail. It s not a foolproof security measure, but it will stop most abuse. You ll send the e-mail, and then redirect the user to the Thank You page. The first thing you do is get the name of the mailing list, using the mailing list id. That s because you want to tell the user in the e-mail which mailing list he or she subscribed to, and it wouldn t be too helpful to say it was mailing list #42. $sql = SELECT listname FROM ml_lists . WHERE ml_id= . $_POST[ ml_id ]; $result = mysql_query($sql, $conn); $row = mysql_fetch_array($result); $listname = $row[ listname ]; Next, you build up the URL that will be at the bottom of the e-mail message. This URL directs the user back to this same page (user_transact.php), this time with an action of confirm (the third action choice, which we ll look at shortly). $url = http:// . $_SERVER[ HTTP_HOST ] . dirname($_SERVER[ PHP_SELF ]) . /user_transact.php?u= . $user_id . &ml= . $_POST[ ml_id ] . &action=confirm ; Then you build the subject and body of the message, concatenating the URL to the bottom, and send it off with the mail() command: $subject = Mailing list confirmation ; $body = Hello . $_POST[ firstname ] . n . Our records indicate that you have subscribed to . the . $listname . mailing list.nn . 507 Mailing Lists
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.