0

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);
  ?>

Edited by peter_budo: Correcting code tags, closing is [/code] not [\code]

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by diafol
0

really? there REALLY is not school, i am trying to learn this on my own. by the way i have yet to find a school that teaches php. now unless you are going to help me, please go away!

0

I have figured it out. Please do not reply to this web, I don't need it anymore!

0
elseif ($res->email == $unsub) //this is where I go wrong!!!!!

Where is this '$unsub' coming from - can't see any reference to it prior to this line.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.