How to check if $var exist in a field
Posted: Fri Dec 26, 2003 4:20 am
I'm creating a register-system right now for mysite, but i have no clue on how to check if a username already exist in the field 'nick'. How could I do it?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$nick = $_GET['nick'];
$query = "SELECT nick FROM users WHERE nick = '$nick'";
$result = mysql_query($query, $link);
$number = mysql_num_rows($result);
if($number == 0) {
print "there's nothing there";
} elseif($number == 1) {
print "someone's already taken that";
} else {
print "uh-oh, somethings wrong, $number people with the same nick!";
}
?>