title: Query to check duplicate value from table using PHP and MySQL
body: <p>I am working on a MySQL query to check duplicate values from table using MySQL and PHP. Let me to explain my table structure and conditions.</p>
  <blockquote>
  <p>db_product_info</p>
  </blockquote>
  <pre><code>pro_id     product_name      product_code      status
  </code></pre>
  <p>The above are my columns in <code>db_product_info</code> table.</p>
  <blockquote>
  <p>conditions:</p>
  </blockquote>
  <p>1-&gt; When table has no value the data should entry in table.</p>
  <p>2-&gt; In same product name only same product code will be inserted for once/multiple time in table.If input will different code for same product name (for more than one entry) it should be checked and return the validation message.</p>
  <p>3- Duplicate of <code>product_code</code> will be checked according to the <code>product_name</code> as explained above.means for same <code>product_name</code> only same product_code should entry multiple time but this <code>product_code</code> should not used for any other <code>product_name</code> .</p>
  <p>Let me show my code below.</p>
  <pre><code> require_once(&quot;../include/dbconfig.php&quot;);
      $result=array();
      $fields=array(&quot;Product_name&quot;,&quot;status&quot;,&quot;product_code&quot;);
      $tablename=PREFIX.&quot;product_info&quot;;
  $values=array($_POST['product_name'],$_POST['status'],$_POST['product_code']);
      $id=db_insert($tablename,$values,$fields);
                     if($id){
                  $result[0][&quot;msg&quot;]=&quot;Added successfully&quot;;
                  $result[0]['id']=$id;
                  echo json_encode($result);
              }else{
                  header(&quot;HTTP/1.0 401 Unauthorized&quot;);
                  $result[0][&quot;msg&quot;]=&quot;Unable to add try again&quot;;
                  $result[0][&quot;data&quot;]=$values;
                  echo json_encode($result);
              }
  </code></pre>
  <p>How can I resolve this problem?</p>