Yet another 'If Statement' problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
codewriter
Forum Newbie
Posts: 6
Joined: Fri Jan 23, 2009 9:41 pm

Yet another 'If Statement' problem

Post 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";
}
}
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Yet another 'If Statement' problem

Post by Benjamin »

No, you'll need to post the code for your file function please.
codewriter
Forum Newbie
Posts: 6
Joined: Fri Jan 23, 2009 9:41 pm

Re: Yet another 'If Statement' problem

Post 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.
codewriter
Forum Newbie
Posts: 6
Joined: Fri Jan 23, 2009 9:41 pm

Re: Yet another 'If Statement' problem

Post 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?
ItsDave
Forum Newbie
Posts: 1
Joined: Sun Jan 18, 2009 11:17 am
Location: Hampshire, UK

Re: Yet another 'If Statement' problem

Post by ItsDave »

If its just a white space, the easiest way would to be to just use trim() to remove it.

Regards.

Dave.
codewriter
Forum Newbie
Posts: 6
Joined: Fri Jan 23, 2009 9:41 pm

Re: Yet another 'If Statement' problem

Post 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
Post Reply