How to check if $var exist in a field
Moderator: General Moderators
How to check if $var exist in a field
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?
Have you tried using the SELECT as you normally would. What's the different by not using it anyhow. Here's something:
-Nay
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!";
}
?>