<?php

session_start();

  include ('../../admin/db/saucerer.php');

  if(isset($_POST['newsletter'])){ 

            if($_POST['username'] != ''){

                $_SESSION['username'] = $_POST['username'];

            }

            else {

  $sql = "SELECT * FROM subscribers WHERE email = '".$_POST['email']."'";
            $query = $conn->query($sql);
            if($query->num_rows > 0){

                echo "<span style='color:#F7931D; font-weight:bold; font-size: 12px;'>Email already registered!</span>";

                //return the inputted fields
                $_SESSION['email'] = $_POST['email'];

            }

            else {

    $email = addslashes($_POST['email']);
    mysqli_query($conn,"insert into `subscribers` (`email`) values ('$email')") or die(mysqli_error());

    if($conn){
  echo "<span style='color:#F7931D; font-weight:bold; font-size: 12px;'>
  Email registered succesfully.
  </span>";
}

else{
  echo "<span style='color:#F7931D; font-weight:bold; font-size: 12px;'>
  Sorry! Your email submission has failed.
  </span>";

     }

    }

  }

}

  
?>






