PDA

View Full Version : Username check


richclare1991
04-16-2012, 03:01 PM
Hi guys, trying to work on a username check so if when filling out the registration form the username is already taken by a user already registered it will echo out a error and stop the process. Ive got other checks working fine on the form just this one im struggling with. Here is the code i am trying
$namecheck = mysql_query("SELECT username FROM members WHERE username = '$username'");
$count = mysql_num_rows($namecheck);
if ($count!=0)
{
echo "Username is already taken please try again!";
}
else

When i run the code the registration page and enter a username that is already taken or that is not taken i get the error -

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in blablabla

Any help appreciated

edbr
04-17-2012, 02:42 AM
this works
<?php $namecheck = 0; // try other numbers
$count =$namecheck;
if ($count>0)
{
echo "Username is already taken please try again!";
}
?>

richclare1991
04-17-2012, 01:10 PM
sorry mate i dont understand, where would i place the query?
thanks for replying

edbr
04-17-2012, 01:27 PM
if the num rows is returning correctly try

$namecheck = mysql_query("SELECT username FROM members WHERE username = '$username'");
$count = mysql_num_rows($namecheck);
if($count>0)
{
echo "Username is already taken please try again!";
}