<?php
$connection = mysql_connect("localhost","*******","******");
if (!$connection) {
die('PHP Mysql database connection could not connect : ' . mysql_error());
}
else{
$db_name = "*****";
mysql_select_db($db_name, $connection);
$result = mysql_query("SELECT email FROM subscribers WHERE email = '".$_POST['email']."'";);
$num_rows = mysql_num_rows($result);
if(isset($_POST['submit'])){
if($_POST['email']!=""){
if ($num_rows > 0) {
echo "email already unsubscribed";
}
else {
$update_sql = "UPDATE subscribers SET unsubscribed = '1' WHERE email = '".$_POST['email']."'";
mysql_query($update_sql, $connection);
echo "<div id='notify' style ='margin-left: auto; margin-right: auto; width: 330px; height: 40px; text-align: center; background-color: #9BFFCD; font-weight: bold; font-family: Verdana, Geneva, sans-serif; padding-top:18px; border: solid #060 thin;'> YOU'RE UNSUBSCRIBED</div>";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Unsubscribe Page</title>
<script>
setTimeout(function(){
document.getElementById('notify').style.display = 'none';
/* or
var item = document.getElementById('notify')
item.parentNode.removeChild(item);
*/
}, 3000);
</script>
</head>
<body>
<div style="margin-left: auto; margin-right: auto; width: 330px; height: 80px; text-align: center; margin-top:100px;">
<div style="height: 30px; margin-bottom: 12px; padding-top: 9px; font-family: Verdana, Geneva, sans-serif; font-size: 11px; text-align: center; background-color:#FBDACE"><strong>CONFIRM UR EMAIL-ID BELOW TO UNSUBSCRIBE</strong><span style="text-align: center"></span></div>
<div style="height: 30px; margin-bottom: 12px; padding-top: 9px; font-family: Verdana, Geneva, sans-serif; font-size: 11px; text-align: center; background-color:#FBDACE">
<form method="post" name="update" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="email" type="text" size="33" /></td>
<td><input name="submit" type="submit" value="Unsubscribe" /></td>
</tr>
</table>
</form>
</div>
</div>
</html>
What I want is when user enters his email id then if it is already exists in table record then it shows an echo message already unsubscribed, otherwise it unsubscribe the user on unsubscribe button click