[PHP] Re: All Queries TRUE even when they should be FALSE

2002-09-20 Thread Philip Hallstrom

Could be wrong, but the fact that $result isn't empty doesn't mean there
are rows... it would be better to say:

if ( !empty($result) ) {
 echo VALID QUERY;
} else {
echo INVALID QUERY;
}

Although you should probably check $result against TRUE and FALSE instead.

If you want to know how many rows have been returned use mysql_num_rows()
(or something very close to that).

good luck!

On Fri, 20 Sep 2002, Monty wrote:

 Even though I have no record in my MySQL DB with that has 005 in the ID
 field, the following statement always reverts to Record Found, or True, no
 matter what ID I use. What's wrong? I'm using PHP 4.2.2. Has something
 changed that makes this work differently? Thanks.

 

 $query = SELECT id FROM member WHERE id = 005;
 $connect = mysql_pconnect(localhost, dbname, password);
 $result = mysql_query( $query, $connect );  // Query DB.

 if ( !empty($result) ) {
 echo RECORD FOUND;
 } else {
 echo RECORD NOT FOUND;
 }



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: All Queries TRUE even when they should be FALSE

2002-09-20 Thread B.C. Lance

you should use mysql_num_rows() to check for records returned instead of 
using mysql_query().

this is because if $query is a valid $sql statement, mysql_query() will 
always return a resource link. which evaluates to true.

so this will work for you:

if (mysql_num_rows($result))
   echo record found;
else
   echo record not found;


--lance

Monty wrote:
 Even though I have no record in my MySQL DB with that has 005 in the ID
 field, the following statement always reverts to Record Found, or True, no
 matter what ID I use. What's wrong? I'm using PHP 4.2.2. Has something
 changed that makes this work differently? Thanks.
 
 
 
 $query = SELECT id FROM member WHERE id = 005;
 $connect = mysql_pconnect(localhost, dbname, password);
 $result = mysql_query( $query, $connect );  // Query DB.
 
 if ( !empty($result) ) {
 echo RECORD FOUND;
 } else {
 echo RECORD NOT FOUND;
 }
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php