Hi guys,
I'm working on my first newsletter script, until now it works.
But I also would like to make a warning in my PHP script that tells the user that he had already entered his email adres.
And I also would like to make the emailadres case sensitive.
How can I do this?
news.php:
<?php
if (isset($POST['action'])) {
$email = $POST['e'];
$email = strip_tags($email);
$email = trim($email);
if (strlen($email) > 255) {
$msg = "Your email<strong>$email</strong> is to long. ";
$msg .= "make it less than 255 chars. ";
} else {
require_once('is_email.inc.php');
if (is_email($email)) {
$action = $_POST['action'];
if ($action === "submit" or $action === "erase") {
if ($action == "submit") {
$sql = "INSERT INTO newsletter (email) VALUES ('$email');";
$msg = "Your <strong>$email</strong> is added. ";
$msg .= "You can remove your email by clicking on the erase-button. ";
$email = "";
}
if ($action == "erase") {
$sql = "DELETE FROM newsletter WHERE email = '$email';";
$msg = "Your emailadres <strong>$email</strong> has been removed. ";
$msg .= "Subscribe yourself by entering your mail in the input-field. ";
}
require_once('connect.php');
$connection = mysql_connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PW) or die("Unable to connect: " . mysql_error());
mysql_select_db("test") or die("Failed to open database: " . mysql_error());
mysql_query($sql) or die("Query failed: " . mysql_error());
mysql_close($connection);
} else {
$email = htmlentities($email, ENT_QUOTES);
$msg = 'Unknown error. ';
$msg .= 'Check your entered email. ';
}
} else {
$email = htmlentities($email, ENT_QUOTES);
if (strlen($email) < 1) {
$msg = "U must enter a <strong>e-mailadres</strong>. ";
} else {
$msg = "<strong>$email</strong> is not a valid mailadres. ";
$msg .= "Check your mail. ";
}
}
}
} else {
$email = "";
$msg = "";
}
?>
Thank you for your help!