title: handling duplicate records in mysql Insert statement
body: <p>Im i have a php form to enter data into a mysql database, my question is how do i handle duplicate records for example if an ID number already exsists how do i check if exsists then if it does throw an error message, for expale saying "ID is already in the database",here is an example of an insert statement, however i would like it to check the database for duplicate records before entering</p>
  
  <pre><code>$values = $_POST;
  foreach ($values as &amp;$value) {
      $value = mysql_real_escape_string($value);
  }
  
  $sql1="INSERT INTO loan (loan_id)
  VALUES ('$values[loan_id]')";
  
  $result = mysql_query($sql1);
  if (!$result) {
      die('Invalid query: ' . mysql_error());
  }
  </code></pre>