Mailing list problem
Posted: Wed Feb 02, 2011 10:05 am
Hey guys, so I could some problems with this mailing list script and it is not doing exactly wut i expect it to do
here's the manage_start.html script:
and this is the manage.php script:
i have tried inserting echo mysqli_num_rows($check_result); right after if (mysqli_num_rows($check_result)<1); for both positive and negative results.
For subscribe, it doesn't matter if i type in a random email address or the one that's actually in the database, the following result always shows up:
dssub8
You have already subscribed!
What is this "dssub8" coming from ? is it related to the "ds" value i assigned?
As for the unsubscribe, it works ok if i type a random email, the result would be:
0
Cannot find your address!
No action is taken
and of coz the "0" is the result of echo mysqli_num_rows($check_result); right after if (mysqli_num_rows($check_result) <1)
but if i wanna delete the actual email address, which is from database, echo shows this:
11
You have unsubscribed!
And the number "11" keeps showing up when I try several DISTINCT emails even tho all the email addresses in database are DISTINCT.
please help me out i am so confused
here's the manage_start.html script:
Code: Select all
<html>
<head>
<title>Sub/Unsub</title>
</head>
<body>
<h3> Subscribe or unsubscribe update mailing list</h3>
<p>Cannot find the results you are looking for? You are then welcomed to subscribe this update mailing list, in which you would receive a notificaiton email once the entry, which has the data you are looking for, is updated. <br><br>
You could also unsubscribe the update mailing list through here if you have previously subscribed.</p>
<form method=POST action="/php/manage.php">
<p><b>Your E-mail address:</b></br><br>
<input type=text name="email" size=40 maxlength=150>
<br><br>
<input type=radio name="action" value="sub" checked>Subscrbie
<input type=radio name="action" value="unsub">Unsubscribe
<input type = "hidden" name = "op" value = "ds">
<br><br><input type=submit name="submit" value="Submit form">
</form>
</body>
</html>
Code: Select all
<?php
//set up a couple of functions
include('connect.php');
function emailChecker($email){
global $connect, $check_result;
//check mail is not already in list
$check = "select id from users where email = '$email'";
$check_result = mysqli_query($connect, $check) or die(mysqli_error($connect));
}
//Determine if they need to see the form or not
if ( ($_POST[op] == "ds" && ($_POST[action] == 'sub'))){
//Try to subscribe, so validate email
echo $_POST[op];
echo $_POST[action];
if($_POST[email]=""){
echo $_POST[email];
hearder("Location: manage_start.php");
exit();
}
//connect to database
db();
//check if email is on the list
emailChecker($_POST[email]);
echo emailChecker($_POST[email]);
//check the number of results to look for duplicates
if (mysqli_num_rows($check_result)<1){
//since no records detected, so add this new email
echo mysqli_num_rows($check_result);
$sql="INSERT into users (email) values('$_POST[email]')";
$result = mysqli_query($connect, $sql) or die(mysqli_error($connect));
echo "<p>Thanks for signing up!!</p>";
} else {
//print failure message
echo mysqli_num_rows($check_result);
echo "<p>You have already subscribed!</p>";
}
} else if (($_POST[op] == 'ds') && ($_POST[action] == "unsub")){
//trying to unsubscribe and validate address
if ($_POST[email] == "") {
header ("Location: manage_start.html");
exit();
}
db();
emailChecker($_POST[email]);
if (mysqli_num_rows($check_result) <1) {
//print failure message
echo mysqli_num_rows($check_result);
echo "<p>Cannot find your address!</p>
<p>No action is taken</p>";
} else {
//unsubscribe address
echo mysqli_num_rows($check_result);
$id = mysqli_real_escape_string($connect, $_POST['id']);
$sql = "DELETE from users where id = '$id'";
$result = mysqli_query($connect, $sql) or die(mysqli_error($connect));
echo mysqli_num_rows($check_result);
echo "<p>You have unsubscribed!</p>";
}
}
?>
For subscribe, it doesn't matter if i type in a random email address or the one that's actually in the database, the following result always shows up:
dssub8
You have already subscribed!
What is this "dssub8" coming from ? is it related to the "ds" value i assigned?
As for the unsubscribe, it works ok if i type a random email, the result would be:
0
Cannot find your address!
No action is taken
and of coz the "0" is the result of echo mysqli_num_rows($check_result); right after if (mysqli_num_rows($check_result) <1)
but if i wanna delete the actual email address, which is from database, echo shows this:
11
You have unsubscribed!
And the number "11" keeps showing up when I try several DISTINCT emails even tho all the email addresses in database are DISTINCT.
please help me out i am so confused