Page 1 of 1

MySQL - checking to see if a user with a certain name exists

Posted: Sun Sep 16, 2007 6:09 pm
by Josh1billion
I'm using the following code to check if a user exists, in the users table, with the username $user.
However, even if $user is blank, the "$result" is always true, when I expected it to be false if there are no results?
What am I doing wrong here?

Code: Select all

$user = strip_tags($_GET['user']);

	$result = mysql_query("SELECT verify_string FROM users WHERE username='$user'");
	if (!$result)
		die("Error in selecting user in verify.php" . mysql_error());

Posted: Sun Sep 16, 2007 6:11 pm
by feyd
No results isn't a query failure.

Posted: Sun Sep 16, 2007 6:12 pm
by Josh1billion
So should I use mysql_num_rows() and check to see if that's 0?

edit: did that; seems to have solved the problem! :)