[Solved] whats wrong with my this php code snippet [closed]


Try changing from this :

$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>";
}

to

if(isset($_POST['submit'])){
    if($_POST['email']!=""){
       $result = mysql_query("SELECT email FROM subscribers WHERE 
      email="".$_POST["email']."' AND unsubscribed ='1'";);
       $num_rows = mysql_num_rows($result);
       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>";
}

Changes :

  1. SELECT query is executed after checking whether the FORM has been POSTed and email field is not empty.
  2. Added unsubscribed = ‘1’ clause in SELECT query otherwise it will fetch records which are not yet unsubscribed.

2

solved whats wrong with my this php code snippet [closed]