title: PHP Error Handling for error: 1062
body: <p>I am pretty new to PHP and hence I am sorry if my query is basic.
  I want some assistance on error handling. </p>
  
  <p>The following PHP code (partial only) inserts data to MySQL table. I have done some reading and found that error 1062 &amp; 1586 &amp; 1859 relate to the Message: Duplicate entry '%s' for key %d. But even after putting this in my code, I am unable to get the code to display the error message I gave below instead of displaying Message: Duplicate entry '%s' for key %d</p>
  
  <p>It always only displays Message: Duplicate entry '%s' for key %d though I have put the error handling in.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;?php
      $con = mysql_connect("localhost","xx","xx");
  
      if (!$con)
      {
          die('Could not connect: ' . mysql_error());
      }
  
  
      if($_POST['podnd'] &gt; 31 || $_POST['podny'] &gt; date("Y") || $_POST['podnm'] &gt; 12)
      {
          die('Error: Check the Dates entered' . mysql_error());
      }
  
      if(strlen($_POST['stagn']) != 7)
      {
          die('Error: Check the tag entered. Service Tag is a 7 charecter alphanumeric code'.mysql_error());
      }
  
      mysql_select_db("software_it", $con);
  
      $sql="INSERT INTO purchaseorders (ServiceTag, PurchaseOrderDate,PurchaseOrderYear,PurchaseOrderMonth) VALUES
          ('$_POST[stagn]','$_POST[podnd]','$_POST[podny]','$_POST[podnm]')";
  
      if (mysql_errno() == 1062 || mysql_errno() == 1586 || mysql_errno() == 1859 || mysql_errno() == 3026) 
      {
          print('Error: New Tags only. Please use other link for updating existing records' );
      }
  
      if (!mysql_query($sql,$con))
      {
          die('Error: ' . mysql_error());
      }
      echo "1 record added";
      mysql_close($con)
      ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>