Hi
I've been struggling with "in_array" for quite a few hours now so I may not be able to see the woods for the trees. I'm trying to create a random number generator that checks and reads an MSSQL db table to check that the number has not been previously used.
Generating the random number is fine. Writing the data to MSSQL is fine. However, if I query the db table , and then try to compare the list of uploaded codes to see if there is already a record, the in_array function gives me incorrect results even though when doing a print_r I can see a match.
I've tried trimming the array entries to remove whitespace etc, but no joy. Am I doing something really stupid ??
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name']))
{
$full = " select current_code from dwtest.dbo.tbxnewcatcodes ";
$fullres = mssql_query($full);
for($aa=0; $bb=mssql_fetch_row($fullres); ++$aa)
{
$already[] = $bb[0];
}
$myfileindex = $uploaddir . $_FILES['userfile']['name'] ;
$emailaddresses = file ($myfileindex);
foreach($emailaddresses as $k=>$v)
{
$trimmed = trim($v);
if(in_array($trimmed,$already))
{
print("Found");
}
}
}
The text file I am uploading contains one record that is in the db table and one that is not.
Any help really appreciated.
Thanks