the code you have shouldn't work...from the php manual:
Assuming the query succeeds, you can call mysql_num_rows() to find out how many rows were returned for a SELECT statment
and:
mysql_query() returns TRUE on success and FALSE on error.
what's happening is that mysql is sometimes throwing an error for some reason. stick with the mysql_num_rows thing...from the manual again:
Code: Select all
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>
and, finally, from a sample validation script I wrote:
Code: Select all
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($affected_rows == 1) {
print "validated";
//add the user to our session variables
$_SESSIONї'username'] = $user_name;
}