Hi,
I have a mailing list script that sends out an e-mail containing a confirmation link when somone signs-up. When the the link is clicked my script should set the 'active' colum to '1'.
For some reason it's deleting the row instead of updating it. I cannot understand how this can happen as I do not use the 'DELETE FROM' sql stament in the part of the script that deals with confirmation.
This is the code that deal with confirmation:
The confirmation link looks like this:
http://dev.junglejar.net/list.php?a=confirm&code=4vh6lfgxyg&artist=Gnosis
THe confirmation section of the script:
case "confirm":
if(isset($_GET['code'])) {
if(mysql_query("SELECT * FROM ".MY_TABLE." WHERE code='".$_GET['code']."' AND artist='".$_GET['artist']."'")) {
mysql_query("UPDATE ".MY_TABLE." SET active = '1' WHERE code = '".$_GET['code']."' AND artist = '".$_GET['artist']."'");
echo "Thank you for confirming, you are now added to the list";
} else {
echo "You have the wrong code or id, please double check";
}
} else {
echo "Please use the link in email to confirm your subscription";
}
break;
Here is the sign-up code:
switch($a) {
case "add":
if(!empty($_POST['email'])) {
$alpha = array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9);
$code = "";
while($i < 10) {
$code .= $alpha[rand(0,count($alpha))];
$i++;
}
trim($code);
if(mysql_num_rows(mysql_query("SELECT * FROM ".MY_TABLE." WHERE email='".$_POST['email']."' AND artist='".$_POST['artist']."'")) != 0) {
echo "You are already on the list.";
exit;
}
mysql_query("INSERT INTO ".MY_TABLE." (email,code,date,artist) VALUES ('".$_POST['email']."','".$code."','".date("U")."','".$_POST['artist']."')") or die(mysql_error());
$message = "Thank you for signing up to the ".$artist." mailing list, to confirm your subscription please visit [url]http://[/url]".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?a=confirm&code=".$code."&artist=".$_POST['artist']." if you did not sign up just ignore this email and you will get no further mailings.";
mail($_POST['email'],$_POST['artist']." Mailing List Confirmation",$message,"From: list-bot@".$_SERVER['SERVER_NAME']);
echo "Thank you for joinging the ".$artist." mailing list/
Check your email and click on the confirmation link to begin receiving mailings.";
} else {
echo "Please enter an email address";
}
break;
I'm really confused! 😕