title: php postgresql check if record already before inserting
body: <p>I cannot figure out the proper wording/syntax for the query statement. I want to check if there is a school already in our table (names schools) that matches the school name. If so, the state it already exists. Any input would be great!</p>
  
  <pre><code>  //create a connection (the connection is made in another php file)
    $obj = new MyConnection();
    $obj-&gt;setConn();
    $obj-&gt;displayValues();
    $qObj = new MyCode();
    $qObj-&gt;setConn( $obj-&gt;getConn());
  
    //Query to put all the school data into db
    $q1 = "INSERT INTO schools(
                   SchoolName,
                   SchoolWebsite,
                   City,
                   State,
                   Locale,
                   Sector,
                   Tuition,
                   GradRate,
                   FacToStudRatio,
                   StudentPop,
                   FreshmenPop,
                   PercentWomen,
                   PercentMen,
                   PercentAdmitted,
                   AverageGpa,
                   AverageScore)
  
          VALUES ('$SchoolName',
                  '$SchoolWebsite',
                  '$City',
                  '$State',
                  '$Locale',
                  '$Sector',
                  '$Tuition',
                  '$GradRate',
                  '$FacToStudRatio',
                  '$StudentPop',
                  '$FreshmenPop',
                  '$PercentWomen',
                  '$PercentMen',
                  '$PercentAdmitted',
                  '$AverageGpa',
                  '$AverageScore')";
  
  
    $findResult = pg_query( 'SELECT * FROM schools WHERE schoolname =.$SchoolName);
  
    if ($findResult != 0) 
    {
      echo "School Record Already Exists&lt;br/&gt;";
      die;
    }
  
    $qObj-&gt;setQuery($q1);
    $qObj-&gt;runQuery();
  </code></pre>