Mailing list (php/mysql)
- Started
- Last post
- 13 Responses
- juhls0
^
- acescence0
your unsubscribe page is missing code to get the values of email and key from the query string. your sql statement is using $email and $email_key, but they are undefined. need to grab values of $_GET['email'] and $_GET['email_key'] first.
as for uniqueness, you can put a unique index on the email field and an insert will fail if it already exists, but you need to read the mysql_errno to see if inserts succeed if you use this method. the other, slower, method is to do a select first with the email address before it's inserted and see if you get anything back.
- juhls0
I put the GET lines in the subscribe page. They actually belong in the unsubscribe page?
Also, I think my unsubscribe link (with the $header area) is incorrect. I tried putting php code within the HTML, and then just resorted to using email=$email, but it's not grabbing anything.
- I took the GET out before posting here though. I'll try that elsewhere.juhls
- acescence0
you're passing the email and key in the URL itself, so yes you need to use GET there. the subscribe form sends it's data via the post method, so you're just using $_POST in that bit of code.
the email not appearing in the unsubscribe link is an issue with quoting. you've got a single-quoted string, which is correct when you want the string to contain double-quotes, as you've got in the href="", but php doesn't look for variables to replace in single-quoted strings. you either have to make it a double-quoted string and escape the contained quotes, or use inline concatenation like this..
- Thank you! I will try all of this out and post again tomorrow. Good night.juhls
- juhls0
Tested it out, and it appends the right email and email key now.
The unsubscribe page comes up with "Error querying database" so I'll have to look into that. Does the syntax look correct on that page?
http://pastebin.com/m5a1a0fca
- juhls0
OK, so I have everything working (including checking for duplicate emails).
Only problem is that I keep getting the message "You are now unsubscribed" even when the email_key does not match the email. It doesn't delete it from the database, which is good. It just doesn't change the message, and I want it to.
- spraycan0
should be easy , pseudo code :
send email to "this" adress if "this" adress exist (if mysql_num_rows==1) in DB DROP the row.
that stuff can be pretty succinct.
- acescence0
mysqli_query will return true if it succeeds and false if not, so you need to check the result of that to see if it's been deleted
- acescence0
right now you're checking if($sql), which will always be true, as you've given $sql a value above
- juhls0
Trying this now:
if($query){
$count = mysqli_affected_rows($oConn);
}
if($count>0){
echo 'You are now unsubscribed.';
}
else{
echo 'Server error. Please try again later or contact the owner of the site.';
}Don't think I am using mysqli_affected_rows properly.