Hello Andy,

Thursday, March 25, 2004, 9:53:05 AM, you wrote:

AB> um....?? this way doesnt work for some strange reason... testing
AB> affected_rows returns always with 0 so:
AB> if(mysql_affected_rows()==0){...}

It depends on your query. If you are doing a SELECT query then you
cannot use affected_rows, you must use num_rows instead. If you are
doing an UPDATE or INSERT query then swap that over.

AB> num_of_rows will always return true and never false i guess because when

mysql_num_rows will never return true OR false because it doesn't return a
boolean, it returns a value, so you cannot check its contents like
this.

AB> $result (the query itself) is "invalid" or returns the fact that the user
AB> typed a wrong username and or password the db server returns NULL, false or
AB> rightfully 0. thus the error:
AB> num_of_rows() is not a valid resource type in:......login.php error

mysql_query ONLY returns a FALSE if the query fails for SELECT queries
(and show/explain/describe, but that's not relevant to this).

If your query is perfectly valid but simply returns no data, you can
only check for this with mysql_num_rows.

Your logic sequence should be as follows:

1. Send query to MySQL

2. Check if mysql_errno == 0
If it DOESN'T, your query had an error, so find out what it was by
echoing out mysql_error() and quitting gracefully.

3. If mysql_errno == 0 then your query ran perfectly, so...

4. Check value of mysql_num_rows. If == 0 then simply no data was
returned, so handle the error accordingly. If value == 1 then you know
you've got the data back that you wanted.

For INSERT/UPDATE queries substitute mysql_num_rows in the above for
affected_rows, principle is the same though - but be careful when
comparing your data types for affected rows.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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

Reply via email to