SELECT DISTINCT still showing duplicate result
<p>I have a HTML <strong>select</strong> form filled by SQL Query using SELECT DISTINCT...
The idea is to not show duplicate values from database, and it's almost working, but in some case it's giving a problem. To fill the SQL columns I'm using a PHP reading a TXT file with delimiters and explode function. If I have in the TXT file 10 duplicate columns, on my HTML  it shows 2, instead of only 1... And I note that 1 is with 9 of the entries from database, and the other one have 1 entry that is always the last line from TXT file.
Resuming: the last line of TXT file always duplicate on the HTML select form.
Checking the database, everything looks ok, I really don't know why it's duplicating always in the last one.
I told about the PHP that make the SQL entry because i'm not sure if the problem is in the PHP that contains the HTML select or in the PHP that fill the database... I believe that the problem is in the PHP with HTML select since I'm looking in the database and everything is ok. The SQL query in this php is like this:</p>

<pre><code>&lt;td class="formstyle"&gt;&lt;select name="basenamelst" class="formstyle" id="basenamelst"&gt;
&lt;option value="Any"&gt;Any&lt;/option&gt;
&lt;?
$sql = mysql_query("SELECT DISTINCT basename FROM dumpsbase where sold=0");
while($row = mysql_fetch_assoc($sql))
  {
    if($row['basename'] == "")
     {
    echo '&lt;option value="'.htmlspecialchars($row['basename'], ENT_QUOTES, 'UTF-8').'"&gt;unknOwn&lt;/option&gt;'; 
     }
    else
     {
       echo '&lt;option value="'.htmlspecialchars($row['basename'], ENT_QUOTES, 'UTF-8').'"&gt;'.htmlspecialchars($row['basename'], ENT_QUOTES, 'UTF-8').'&lt;/option&gt;'; 
     }
   }
?&gt;
&lt;/select&gt;
</code></pre>

<p>Remember: if I upload to database 10 duplicate columns, it shows 2 on select. One with 9 entries, and another with 1 entry (always the last line of my TXT file)...
Okay, many people told me to trim() the columns and it still showing duplicate... So I came to the conclusion that I have some issue while loading the TXT for database. Here is the code where I get the values to put on database:</p>

<pre><code>$file = fopen($targetpath, "r") or exit("Unable to open uploaded file!");

while(!feof($file))
 {
   $line = fgets($file);
   $details = explode(" | ", $line);

   foreach($details as &amp;$value) // clean each field
    {
      $value = mysql_real_escape_string($value);
      if($value == "")
     {
       $value = "NONE";
     }
     }
   unset($value);
 mysql_query("INSERT INTO dumpsbase VALUES('NULL', '$details[0]', '$details[1]', '$details[2]', '$details[3]', '$details[4]', '0', '$price', 'NONE', now(), 'NONE', 'NONE')") or die ("Uploading Error!");
</code></pre>
