I am trying to upload data from a text file to a 2 dbs after passing through a duplicate check function. The problem is that my dup func does not seem to be comparing the strings appropriately and catching the duplicates. I'm not php illiterate, but am far from guru status so I tend to steer clear of reg exp whenever possible. However, if no one can help me with the current script format then I would appreciate some assistance with generating a $pattern for preg_match. The current duplicate function is as follows:
function comp_dupcheck2($acro, $comp_orig) {
$y = 1;
$comp = strtolower($comp_orig);
update_connect();
$query = mysql_query("select * from companylist");
while ($cname = mysql_fetch_assoc($query)) {
$compdb = strtolower($cname['cname']);
if ($compdb != $comp) {
echo 'No duplicate found.';
return false;
}
else {
echo $comp .' already exists...';
return true;
break;
}
}
mysql_free_result($query);
}
Another post mentioned that string comparisons tend to be a little tricky and that even things like using double versus single quotes can alter string values. I tried to keep it consistent. Here is my upload script:
$filename = "cur_jobs.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
echo '<table width="800" align="center">
<tr>
<td>TITLE</td>
<td>COMPPANY</td>
<td>LOCATION</td>
<td>PATH</td>
<td>POSTDATE</td>
</tr>';
//newsletter_connect();
$type = "job";
$status = "active";
$line = 1;
$i=0;
while ($i < 210) {
$job = explode("*", $contents);
$title = $job[$i];
$i++;
$compname = $job[$i];
$i++;
$loc = $job[$i];
$i++;
$path = $job[$i];
$i++;
$postdate = $job[$i];
$i++;
echo '<tr>
<td>' . $line . ': ' . $title . '</td>
<td>' . $compname . '</td>
<td>' . $loc . '</td>
<td>' . $path . '</td>
<td>' . $postdate . '</td>
</tr>';
$line += 5;
$acro = company_acro2($compname);
if (comp_dupcheck2($acro, $compname) == false) {
//addcomp($compname, $acro);
}
$compid = getcompid($acro);
$postdate = datereformat($postdate);
$end = findenddate($postdate);
//$add = mysql_query("insert into careers (id, type, title, comp_id, location, path, postdate, enddate, status, timestamp) values (default, '$type', '$title', '$compid', '$loc', '$path', '$postdate', '$end', '$status', default)")or die(mysql_error());
}
echo '</table>';
I tried to get rid of the extra junk (like echos and prints) I used for testing but I may have missed some, and the actual upload portion has been hidden, but otherwise is pretty straightforward.
I have tried doing the search on the mysql end using:
$query=mysql_query("select * from companylist where cname='$comp'");
//OR
$query=mysql_query("select * from companylist where cname like '$comp'")
if (mysql_num_rows($query) == 0) {...}
I also tried breaking the names into arrays and comparing them character by character. Neither option would detect the duplication.
I would appreciate any suggestions from the audience or the wizards. Thanks in advance for the help.