title: PHP how to check if record exist (PDO)
body: <p>i try to do insert when record is not exist with the following</p>
  
  <pre><code>$query = $db-&gt;query("SELECT * FROM people WHERE first_name = :first_name");
  $statement = $db-&gt;prepare($query);
  $statement-&gt;execute();
  $count = $statement-&gt;fetchColumn();
  if ($count === 1)
  {
      echo "First name Exist";
  }
  else
  {
      $query = "INSERT INTO people (first_name, last_name) VALUES (:first_name, :last_name)";
      for($count = 0; $count&lt;count($_POST['hidden_first_name']); $count++)
      {
      $data = array(
      ':first_name' =&gt; $_POST['hidden_first_name'][$count],
      ':last_name' =&gt; $_POST['hidden_last_name'][$count]
      );
      $statement = $db-&gt;prepare($query);
      $statement-&gt;execute($data);
      }  
  }
  </code></pre>
  
  <p>it still inserting to database that makes duplicate first name. and also try accepted answer found <a href="https://stackoverflow.com/questions/26863879/check-if-record-exists-pdo">here</a> but i can't make it work.</p>