Just can't seem to get this script to work... It adds the username and password to the database, but can't get it to remove it.
<?php
$name = "";
$email = "";
$msg_to_user = "";
if ($_POST['name'] != "") {
include_once "connect_to_mysql.php";
$name = $_POST['name'];
$email = $_POST['email'];
$name = stripslashes($name);
$mail = stripslashes($email);
$name = stripcslashes($name);
$email = stripcslashes($email);
$name = strip_tags($name);
$email = strip_tags($email);
$sql = mysql_query("SELECT * FROM newsletter WHERE email='$email'");
$numRows = mysql_num_rows($sql);
if (!$email) {
$msg_to_user = '<br /><br /><h4><font color="FF0000">Please type an email address ' . $name . '.</font></h4>';
} else if ($numRows > 0) {
$msg_to_user = '<br /><br /><h4><font color="FF0000">' . $email . ' is already in the system.</font></h4>';
} else {
$sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime)
VALUES('$name','$email',now() )") or die (mysql_error());
$msg_to_user = '<br /><br /><h4><font color="0066FF">Thanks ' . $name . ', you have been added successfully.</font></h4>';
$name = "";
$email = "";
}
}
?>
<html>
<head>
<title>Subscribe to Our Newsletter</title>
<script language="php" language="javascript">
function unsubscribe()
{
include_once "connect_to_mysql.php";
$email = $_GET['email'];
$sql_delete = mysql_query("DELETE FROM newsletter WHERE email='$email' LIMIT 1");
if (!$sql_delete) {
$msg_to_user = "Sorry there seems to be trouble removing your listing. Please email Admin directly using this email address: put an email address here";
} else {
$msg_to_user = "It is done. You will not receive our newsletter ever again unless you relist.";
}
}
</script>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p style="font-size: 14px; color:#F00">Newsletter:</p>
<table width="200">
<tr>
<td><span id="sprytextfield1">
<input onClick="this.value='';" name="name" type="text" value="Your Name..." size="25">
</span></td>
</td>
<tr>
<td><span id="sprytextfield2">
<input onClick="this.value='';" name="email" type="text" value="Email address..." size="25">
</span></td>
</tr>
</table>
<input name="mySubmitBtn" type="submit" value="Subscribe">
<input name="unsub" type="button" onClick="unsubscribe()" value="Unsubscribe">
</form>
<?php echo $msg_to_user; ?>
</body>
</html>
<?php
$name = "";
$email = "";
$msg_to_user = "";
if ($_POST['name'] != "") {
include_once "connect_to_mysql.php";
$name = $_POST['name'];
$email = $_POST['email'];
$name = stripslashes($name);
$mail = stripslashes($email);
$name = stripcslashes($name);
$email = stripcslashes($email);
$name = strip_tags($name);
$email = strip_tags($email);
$sql = mysql_query("SELECT * FROM newsletter WHERE email='$email'");
$numRows = mysql_num_rows($sql);
if (!$email) {
$msg_to_user = '<br /><br /><h4><font color="FF0000">Please type an email address ' . $name . '.</font></h4>';
} else if ($numRows > 0) {
$msg_to_user = '<br /><br /><h4><font color="FF0000">' . $email . ' is already in the system.</font></h4>';
} else {
$sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime)
VALUES('$name','$email',now() )") or die (mysql_error());
$msg_to_user = '<br /><br /><h4><font color="0066FF">Thanks ' . $name . ', you have been added successfully.</font></h4>';
$name = "";
$email = "";
}
}
?>
<html>
<head>
<title>Subscribe to Our Newsletter</title>
<script language="php" language="javascript">
function unsubscribe()
{
include_once "connect_to_mysql.php";
$email = $_GET['email'];
$sql_delete = mysql_query("DELETE FROM newsletter WHERE email='$email' LIMIT 1");
if (!$sql_delete) {
$msg_to_user = "Sorry there seems to be trouble removing your listing. Please email Admin directly using this email address: put an email address here";
} else {
$msg_to_user = "It is done. You will not receive our newsletter ever again unless you relist.";
}
}
</script>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p style="font-size: 14px; color:#F00">Newsletter:</p>
<table width="200">
<tr>
<td><span id="sprytextfield1">
<input onClick="this.value='';" name="name" type="text" value="Your Name..." size="25">
</span></td>
</td>
<tr>
<td><span id="sprytextfield2">
<input onClick="this.value='';" name="email" type="text" value="Email address..." size="25">
</span></td>
</tr>
</table>
<input name="mySubmitBtn" type="submit" value="Subscribe">
<input name="unsub" type="button" onClick="unsubscribe()" value="Unsubscribe">
</form>
<?php echo $msg_to_user; ?>
</body>
</html>