RE: [PHP] mysql_num_rows always returns 1?

2002-06-18 Thread Niklas Lampén

Try

$query = select count(*) as Lines from users where 
  
and then check the value of Lines. Or then do something like

$query = select ID from users where 
and now your mysql_num_rows($result) should return right kinda value.


Niklas

-Original Message-
From: Mark Colvin [mailto:[EMAIL PROTECTED]] 
Sent: 18. kesäkuuta 2002 15:00
To: [EMAIL PROTECTED]
Subject: [PHP] mysql_num_rows always returns 1?


The function below works when I pass in a valid username and password
and returns '1'. When I pass a username and password that is not in the
database it still returns '1'. I have put some echo statements in for
debugging and the value of $numresult is always '1'. Does mysql_num_rows
retain results in memory or something like that or am I completely going
down the wrong road?

  function VerifyLogin($user, $pass)
  {

 $conn = $this-DB_Connect();

 $query = select count(*) from users where 
   .username = '$user' and 
   .password = '$pass';

 $result = mysql_query($query);

 if(!$result)
 {
 echo 'Cannot run query.';
 echo 'user = ' .$user;
 echo 'pass = ' .$pass;
 echo 'query = ' .$query;
 echo 'result = ' .$result;
 $numresult = mysql_num_rows($result);
 echo 'numresult = ' .$numresult;
 exit;
 }
 else
 {
 $numresult = mysql_num_rows($result);
 echo 'numresult = ' .$numresult;
 }

 //if a row exists we have a correct username/password
 if (mysql_num_rows($result) == 1)
 {
return 1;
 }
 // else username and/or password is wrong
 {
return 0;
 }
  }

Thanks in advance


Mark



This e-mail is intended for the recipient only and
may contain confidential information. If you are
not the intended recipient then you should reply
to the sender and take no further ation based
upon the content of the message.
Internet e-mails are not necessarily secure and
CCM Limited does not accept any responsibility
for changes made to this message. 
Although checks have been made to ensure this
message and any attchments are free from viruses
the recipient should ensure that this is the case.


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

###
This message has been scanned by F-Secure Anti-Virus for Internet Mail.
For more information, connect to http://www.F-Secure.com/

###
This message has been scanned by F-Secure Anti-Virus for Internet Mail.
For more information, connect to http://www.F-Secure.com/

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




Re: [PHP] mysql_num_rows always returns 1?

2002-06-18 Thread Eugene Mah

At 13:00 18-06-02 +0100, Mark Colvin wrote:
The function below works when I pass in a valid username and password and
returns '1'. When I pass a username and password that is not in the database
it still returns '1'. I have put some echo statements in for debugging and
the value of $numresult is always '1'. Does mysql_num_rows retain results in
memory or something like that or am I completely going down the wrong road?

that's because when 'select count(*)' = 0 when it finds no results.
So you get a record returned to $result with a single line that tells
you count(*) was 0.

what you should probably do is instead of counting, check for a valid
username/password returned by your query.  if they're blank, then
$user/$pass are either incorrect or not in your users table.

or, as someone else suggested, check the value of count(*)
rather than the number of lines returned by the query.

Eugene

--
-
Eugene Mah, M.Sc., DABR   [EMAIL PROTECTED]
Medical Physicist/Misplaced Canuck[EMAIL PROTECTED]
Department of Radiology   For I am a Bear of Very Little
Medical University of South Carolina   Brain, and long words Bother
Charleston, South Carolina me.   Winnie the Pooh
http://home.netcom.com/~eugenem/
PGP KeyID = 0x1F9779FD, 0x319393F4
PGP keys available on request ICQ 3113529 O-
-


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




RE: [PHP] mysql_num_rows always returns 1?

2002-06-18 Thread David Freeman


   $query = select count(*) from users where 

You are asking for a count() in your query.  This will always give you
one row returned with a count.  If you really want to do this you should
probably have:

  $query = select count(*) as usercount from users where

Then you can do your tests based on the value of usercount.

Alternately, you could do something like this:

  $query = select * from user where

And then use mysql_num_rows() to see how many users you got.  In this
case, no matches will result in no rows returned.

CYA, Dave




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