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

oh god is ther a school learing that
i hop to join it
relly

I said "not for school"!

i know but "not for school" mean there is a school

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!

i'm with the php from 4 years
learing from the internet

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

Member Avatar for diafol
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.