Specifications
unsubscribe(get_email(), $id);
display_items(“Subscribed Lists”, get_subscribed_lists(get_email()),
‘information’, ‘show-archive’, ‘unsubscribe’);
break;
}
In each case, we call a function (subscribe() or unsubscribe()) and then redisplay a list of
mailing lists the user is now subscribed to using the display_items() function again.
The subscribe() and unsubscribe() functions are shown in Listing 28.11.
LISTING 28.11 subscribe() and unsubscribe() Functions from mlm_fns.php—These
Functions Add and Remove Subscriptions for a User
function subscribe($email, $listid)
{
if(!$email||!$listid||!list_exists($listid)||!subscriber_exists($email))
return false;
//if already subscribed exit
if(subscribed($email, $listid))
return false;
if(!db_connect())
return false;
$query = “insert into sub_lists values (‘$email’, $listid)”;
$result = mysql_query($query);
return $result;
}
function unsubscribe($email, $listid)
{
if(!$email||!$listid)
return false;
if(!db_connect())
return false;
$query = “delete from sub_lists where email = ‘$email’ and listid = $listid”;
Building Practical PHP and MySQL Projects
P
ART V
688
34 7842 CH28 3/6/01 3:46 PM Page 688