Page 1 of 1

Yet another 'If Statement' problem

Posted: Sun Jan 25, 2009 11:58 am
by codewriter
Anyone know why this code wont work? Any help would be greatly appreciated.

Code: Select all

 
$productsdbtt=file("inc/DB/Products.txt");
foreach($productsdbtt as $key1tt => $val1tt) 
{$productstt[$key1tt] = explode("||", $val1tt);}
for($htt = 0; $htt < sizeof($productsdbtt); $htt++) 
{
if ($currentusername==$productstt[$htt][8])
{
echo "Match";
}
}
 

Re: Yet another 'If Statement' problem

Posted: Sun Jan 25, 2009 2:03 pm
by Benjamin
No, you'll need to post the code for your file function please.

Re: Yet another 'If Statement' problem

Posted: Sun Jan 25, 2009 2:25 pm
by codewriter
That is pretty much all of the code. Forgot to mention that i checked whether $productstt[$htt][8] and $currentusername had any value and they were both what i expected them to be.

Re: Yet another 'If Statement' problem

Posted: Sun Jan 25, 2009 7:17 pm
by codewriter
Seem to have found the problem, now for the solution.
Different code, but the same purpose:

Code: Select all

 
$productsdb=file("Database/Usersfile.txt");
 
foreach($productsdb as $key1=>$val1) 
{$products[$key1]=explode("||",$val1);}
 
for($k1=0;$k1<sizeof($productsdb);$k1++) 
{
$selleruser2=$_POST["selleruser"];
 
if ($selleruser2==$products[$k1][0])
{
echo "match";
}
}
 
The code adds a space after the $selleruser2 variable. Does anyone know the solution? Please?

Re: Yet another 'If Statement' problem

Posted: Sun Jan 25, 2009 7:19 pm
by ItsDave
If its just a white space, the easiest way would to be to just use trim() to remove it.

Regards.

Dave.

Re: Yet another 'If Statement' problem

Posted: Sun Jan 25, 2009 7:28 pm
by codewriter
Thankyou very much. The laptop was just about to get another new experience, falling the 20 feet out of the window to the floor if a solution wasnt found :D