mySQL SELECT matches empty fields, not sure why?

Associate
Joined
15 Feb 2006
Posts
1,872
Location
hell
Hi guys

I have another fairly simple question (I guess!).

Basically I've written this statement in PHP:

$finduserid="SELECT player_id from Player WHERE username = '$username'";
$player_id = mysql_query($finduserid);

while( $row = mysql_fetch_array($player_id))
{

echo ($row['player_id'] . "<br />");


}


The problem is I have some username rows in my mySQL table that are blank.

When I loop through and echo out all the player_ids that are found (which should only be one), the query lists all the blank fields too.

Why is mySQL matching against blank fields, if I've specified a username for it to look for in the table?

Many thanks
 
Echo out the actual query:

PHP:
$finduserid="SELECT player_id from Player WHERE username = '$username'";
echo $finduserid;
$player_id = mysql_query($finduserid);

And then run the query it in whatever database admin tool you use (phpmyadmin, navicat, sqlpro, mysql workbench etc.) If you get the same results then you have a problem in the query somewhere. Either way you should be able to identify the problem quite quickly.
 
Back
Top Bottom