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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Josh1billion
Forum Contributor
Posts: 316
Joined: Tue Sep 11, 2007 3:25 pm

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

Post 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());
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

No results isn't a query failure.
User avatar
Josh1billion
Forum Contributor
Posts: 316
Joined: Tue Sep 11, 2007 3:25 pm

Post 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! :)
Post Reply