<?php
function doDB() {
global $conn;
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("skidmore",$conn) or die(mysql_error());
}
function emailChecker($email) {
global $conn, $check_result;
$check = "select id from subscribers where email = '$email'";
$check_result = mysql_query($check,$conn) or die(mysql_error());
}
if ($_POST[op] != "ds") {
$display_block = "
<form method=POST action=\"$_SERVER[PHP_SELF]\">
<p><strong>Your E-Mail Address:</strong><br>
<input type=text name=\"email\" size=40 maxlength=150>
<p><strong>Action:</strong><br>
<input type=radio name=\"action\" value=\"sub\" checked> subscribe
<input type=radio name=\"action\" value=\"unsub\"> unsubscribe
<input type=\"hidden\" name=\"op\" value=\"ds\">
<p><input type=submit name=\"submit\" value=\"Submit Form\"></p>
</form>";
} else if (($POST[op] == "ds") && ($POST[action] == "sub")) {
if ($_POST[email] == "") {
header("Location: manage.php");
exit;
}
doDB();
emailChecker($_POST[email]);
if (mysql_num_rows($check_result) < 1) {
$sql = "insert into subscribers values('', '$_POST[email]')";
$result = mysql_query($sql,$conn) or die(mysql_error());
$display_block = "<P>Thanks for signing up!</P>";
} else {
$display_block = "<P>You're already subscribed!</P>";
}
} else if (($POST[op] == "ds") && ($POST[action] == "unsub")) {
if ($_POST[email] == "") {
header("Location: manage.php");
exit;
}
doDB();
emailChecker($_POST[email]);
if (mysql_num_rows($check_result) < 1) {
$display_block = "<P>Couldn't find your address!</P>
<P>No action was taken.</P>";
} else {
$id = mysql_result($check_result, 0, "id");
$sql = "delete from subscribers where id = '$id'";
$result = mysql_query($sql,$conn) or die(mysql_error());
$display_block = "<P>You're unsubscribed!</p>";
}
}
?>
<HTML>
<HEAD>
<TITLE>Subscribe/Unsubscribe</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
color: #000000;
font-weight: bold;
}
body {
background-color: #669933;
}
a {
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #ffffff;
}
a:active {
color: #000000;
}
h1,h2,h3,h4,h5,h6 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
h1 {
font-size: large;
color: #000000;
}
-->
</style></head>
<BODY>
<h1>Subscribe/Unsubscribe</h1>
<?php echo "$display_block"; ?>
</BODY>
</HTML>