// connect to db $db = mysql_connect("mysql.serve.com", "i-claudius", "trep01") or die ("Couldn't connect."); mysql_select_db("GENERAL", $db) or die ("Couldn't select db."); if ($op != "ds") { //they need to subscribe or unsubscribe $text_block = "
"; } else if (($op == "ds") && ($action == "sub")) { // check they're not already subscribed, // then subscribe them or return message $check = "select email_addr from mailing where email_addr = \"$email\""; $check_result = mysql_query($check) or die("Can't execute check e-mail address."); $check_num = mysql_num_rows($check_result); if ($check_num == 0) { // if $check_num is 0, then no match was found, // and the user should be subscribed $sql = "insert into mailing values(\"$email\")"; @mysql_query($sql) or die ("Couldn't insert email."); $text_block = "Thanks for signing up!
"; } else { // if $check_num is not 0, then the user is // already subscribed, and you should let // them know it. $text_block = "You're already subscribed!
"; } } else if (($op == "ds") && ($action == "unsub")) { // check they're already subscribed, // then unsubscribe them or return message $check = "select email_addr from mailing where email_addr = \"$email\""; $check_result = mysql_query($check) or die("Can't execute check e-mail address."); $check_num = mysql_num_rows($check_result); if ($check_num == 0) { // if $check_num is 0, then no match was found, // and the user cannot be unsubscribed $text_block = "Couldn't find your e-mail on the list!
You haven't been unsubscribed, because the e-mail you entered is not in the database."; } else { // if $check_num is not 0, then the user is // on the list, so can be unsubscribed. $sql = "delete from mailing where email_addr = \"$email\""; @mysql_query($sql) or die ("Couldn't delete email."); $text_block = "
You're unsubscribed!
"; } } ?>Subscribe to the newsletter