First let me start off with saying I am just learning PHP with smarty and am not doing this for any school/class assignment.
I am trying to create an email form that allows a user to subscribe/unsubscribe from a mailing list.
I can not figure out how to write the unsubscribe part. I used if/elseif/else:
<?php
require_once 'include/Smarty/libs/Smarty.class.php';
require_once 'include/Database.inc.php';
$smarty = new Smarty();
define ('TEMPLATE', 'manage.html');
$email = $_POST['email'];
// check email against db
if (!empty($_POST['email']))
{
$query = 'SELECT id
FROM subscribers
WHERE email = \''.$_POST['email'].'\'';
$res = $db->query($query);
// do they exist? yes
if ($res->numRows() > 0)
{
$message = 'Our records indicate that you are subscribed.';
}
// unsubscribe
elseif ($res->email == $unsub) //this is where I go wrong!!!!!
{
$query = 'DELETE FROM subscribers
WHERE email = \''.$_POST['email'].'\'';
$message = 'You have been unsubscribed';
}
else {
// they don't exist, enter new record
$query = 'INSERT INTO subscribers
SET email = \''.$_POST['email'].'\'';
$message = 'Thank You!';
}
}
$smarty->assign(array(
'title' => 'E-Mail Form',
'message' => $message
));
$smarty->display(TEMPLATE);
?>