title: Mysql Trigger comes up with error
body: <p>I have this trigger which should do this : </p>
  
  <p>BEFORE a new entry is created in the entry log table , it will take the driver_id from that table , put it into the if statement and then set the allowed field from the new entry to either Y or No based on the outcome .</p>
  
  <pre><code>    create trigger xxx before insert on entrylog for each row
  if  exists (select *
                from driver
                join card_driver
                  on driver.id = card_driver.driver_id
                join card
                  on card_driver.card_id = card.id
               where driver.id = new.driver_id) then
      set new.allowed = 'Y';
  end if
  </code></pre>
  
  <p>The only problem is that it dosent work . I keep getting this error if I try an put it into phpmyadmin : </p>
  
  <pre><code>    Error
  
  SQL query: Documentation
  
  CREATE trigger allowedupdate before INSERT ON entrylog
  FOR each
  ROW
  IF EXISTS (
  
  SELECT *
  FROM driver
  JOIN card_driver ON driver.id = card_driver.driver_id
  JOIN card ON card_driver.card_id = card.id
  WHERE driver.id = new.driver_id
  )
  THEN
  SET new.allowed = 'Y';
  
  MySQL said: Documentation
  #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9 
  </code></pre>
  
  <p>The if statement is taken from this and should produce the same outcome (just not echoing messages)</p>
  
  <pre><code>$sql ="SELECT *
    FROM driver AS d 
  INNER
    JOIN card_driver AS cd
      ON cd.driver_id = d.id
  INNER
    JOIN card AS c
      ON c.id = cd.card_id     
   WHERE d.ID = $id";
  mysql_select_db('damp');
  $result = mysql_query( $sql, $conn );
  $row = mysql_fetch_assoc($result);
  switch($row['state_id'])
  {
  case "1":
     echo "&lt;strong&gt;&lt;font color=\"green\"&gt;Authorisation Granted!&lt;/font&gt;&lt;/strong&gt;";
     break; // This should be a Y , the rest are N
  case "2":
     echo "&lt;strong&gt;&lt;font color=\"red\"&gt;Your card has expired and authorisation is denied&lt;/font&gt;&lt;/strong&gt;";
     break;
  case "3":
     echo "&lt;strong&gt;&lt;font color=\"red\"&gt;Your card has been cancelled and authorisation is denied&lt;/font&gt;&lt;/strong&gt;";
     break;
  default:
     echo "&lt;strong&gt;&lt;font color=\"red\"&gt;The Card ID does not exist&lt;/font&gt;&lt;/strong&gt;";
  }
  </code></pre>