Re: MySQL frustration
| From: | Andrian Pervazov | Date: | Tue, 18 Jul 2000 02:56:57 +0000 |
| Subject: | Re: MySQL frustration | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-7009@lists.php.net to get a copy of this message | ||
Tom Peck wrote:
>
> Good afternoon everyone
>
> I'm tearing my hair out over this one - it seems so simple - but it's not
> doing what it's told... All I want to do is check if $tempName exists in
> the database - and if it doesn't I want to know. BUT no matter what i have
> tried - it either doesn't think it exists when it does - or the opposite.
> This is the latest piece of code I have been trying - can anyone find any
> problems with it? It seems that $result is always true - no matter what
> $tempName is equal to. How is this possible?
>
> Thanks for any help.
>
> // The frustrating code
>
> $tempName = "This Person";
>
> $sql = "SELECT * FROM tblPlayers WHERE fldName='$tempName'";
> $result = mysql_query($sql);
>
> if ( $result ) {
> echo "<br> RESULT TRUE!";
> }
>
> else
>
> echo "<br> RESULT FALSE!";
> }
if ($result) will be alway true - it just means that the query was
performed without a problem whether it returned matches or not. To check
whether matches were found use this:
if (mysql_num_rows($res))
Andrian