title: Skip duplicate values when importing CSV data
body: <p>I have a <strong>csv</strong> file with <strong>2</strong> columns (Company Name, Customer Name). I insert company_name in <strong>tbl_company</strong> and customer_name and company_id in <strong>tbl_customer</strong>. So company_id is the foreign key in tbl_customer. Now the problem I am facing is that I dont want to insert company name more than 1 time in my tbl_company. Can anyone please check the code where I write this condition.</p>
  
  <p>My PHP code</p>
  
  <pre><code>$filename=$_FILES["file"]["tmp_name"];
      if($_FILES["file"]["size"] &gt; 0)
      {
          $file = fopen($filename, "r");
          $x = 0;
          while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
          {
                      ini_set('max_execution_time', 300);
                      if($x &gt; 0) {
                      // Insert company name into company table
                      $sql_comp = "INSERT into tbl_company(company_name) values ('$emapData[0]')";
                      mysql_query($sql_comp);
                      //$lastID = mysql_insert_id();
                      // get last ID from tbl_company and insert as foreign key in tbl_customer
                      $sql_LID = "SELECT * FROM tbl_company ORDER BY id DESC";
                      $res_LID = mysql_query($sql_LID);
                      $row_LID = mysql_fetch_array($res_LID);
                      $lastID = $row_LID['id'];
                      // insert company id and customer name into table customer
                      $sql_cust = "INSERT into tbl_customer(comp_id,customer_name) values ('$lastID', '$emapData[1]')";
                      mysql_query($sql_cust);
                      }
                      $x++;
          }
          fclose($file);
          echo 'CSV File has been successfully Imported';
          header('Location: index.php');
      }
  </code></pre>