title: IF NOT EXISTS then INSERT else show message not working
body: <p>I have a table with 'reference' in it, the idea is that if a reference exists already, then it doesn't insert. If it doesn't exist then it does insert. But this code just doesn't insert either way. Assist please.</p>
  
  <pre><code>$dbconn = pg_connect("host=127.0.0.1 dbname=XX user=XX password=XX") or die('Could not connect: ' . pg_last_error());
  $query = "IF NOT EXISTS (SELECT reference FROM card WHERE reference = '$reference')
  INSERT INTO staff (reference, first_name, last_name, address1, address2, address3, address4)
  VALUES ('$reference', '$first_name', '$last_name', '$address1', '$address2', '$address3', '$address4')";
  
  $result = pg_query($query);
      if (!$result)  
  {  
  echo "Customer update failed!! This ID might already be registered with us. Please go back and check the spelling of your email address.&lt;br&gt;&lt;br&gt;&lt;input type=\"button\" value=\"Go Back\" onClick=\"history.go(-1);return true;\"&gt;"; 
  die; 
  } else  
  {  
  echo "Customer update successful; ";  
  }  
  
  pg_close(); 
  </code></pre>