<?php
if($_POST['subscriber_submit']){
//echo "submitted";
    $email_address = mysql_real_escape_string($_POST['email']);

	if(!empty($email_address) && filter_var($email_address, FILTER_VALIDATE_EMAIL)){
        //check if already subscribed
        $sql22 = "select * from email_subscribers where email_address='$email_address'";
        $rt22=mysql_query($sql22);
        if(mysql_num_rows($rt22)>0){
            $subscribe_alert_msg= "<center>That email address is already subscribed!</center>";
        } else {
            //all should be filled in correctly...
            $query = "insert into email_subscribers (email_address) values ('$email_address')";
            mysql_query($query);
            $subscribe_alert_msg= "<center>Thanks for subscribing! <br>Be sure to watch for upcoming deals!</center>";
        }
	} else {
		$subscribe_alert_msg= "<center>Please enter a valid email address.</center>";
	}
}
?>
<div style="width:200px;">
<?php 
if(!empty( $subscribe_alert_msg)){
	echo "<font color='red'>".$subscribe_alert_msg."</font>";
} else {
	echo "<center>Subscribe to email updates & newsletters:</center>";
}
?>
<form action="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>" method="post">
<center><input type="text" name="email" size="15"></center>
<center><input type="submit" name="subscriber_submit" value="Subscribe"></center>
</form>
</div>

