I change script significantly now the only problem when I insert an email address and press "'subscribute" if it already exist in DB:
DOES NOT APPEAR:
"This email address ( $email ) already exist, in the database !"
BUT APPEAR:
""You have successfully Subscribute to our 'Newsletter (Latest Offers)' as: \n". $email"
well ?
Code:
<td align="center" valign="middle"><h1 class="text_normal15px">
<?php
$email = $_POST['email-news'];
include("../dbinfo.php");
$linkid = @mysql_connect($hostname,$username,$password) or die( "Unable to connect to Database Server. Please try again later.");
@mysql_select_db($database,$linkid) or die( "Unable to select database. Please try again later,"); // @
if ($_POST['unsubscribute']) {
$query = "SELECT * FROM $NewslettersTable";
$result = @mysql_query($query,$linkid) or die("Unable to execute query. Please try again later.");
$count = @mysql_num_rows($result);
// echo $count;
$f = "n";
for ($j=0;$j<$count;$j++) {
$row = mysql_fetch_row($result);
if ($email == $row[1]) { // "info2@poliscarhire.com"
$f = "y";
break;
}
}
if ($f != "y") {
echo "This email address ( $email ) does NOT exist, in the database !";
} else {
$query = "DELETE FROM $NewslettersTable WHERE email='$email'";
$result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");
echo "You have successfully UnSubscribute from our 'Newsletter (Latest Offers)' as: \n". $email;
}
}
else {
if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z\.]{2,4}", $email)) { // "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
$query = "SELECT * FROM $NewslettersTable";
$result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");
$count = @mysql_num_rows($result);
$f2 = "n";
if ($count > 0) {
for ($j=0;$j<$count;$j++) {
$row = mysql_fetch_row($result);
if ($email == $row[1]) { // 'email'
echo "This email address ( $email ) already exist, in the database !";
$f2 = "y";
break;
}
} // end for
} // end if
// mysql_free_result($result);
if ($f2 == "n") {
$query = "INSERT INTO $NewslettersTable VALUES(NULL,'$email')";
$result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");
echo "You have successfully Subscribute to our 'Newsletter (Latest Offers)' as: \n". $email;
}
} else {
echo "InValid email address. Please retry !";
} // end if
} // end if main
// mysql_free_result($result);
mysql_close($linkid);
?></h1>
Bookmarks