Jump to content

check if username exist in datebase ?


omar-do

Recommended Posts

$checkuser = mysql_query("SELECT id FROM $tbl WHERE username = ".$_POST['username']." LIMIT 1 ");

 

        if ($checkuser){

          $row =  mysql_num_rows($checkuser);

            print 'username exist.';

 

        }

 

what's wrong ? when i click submit an username that is in the database its doesn't  print 'username exist.' and the username goes in the database ...

Link to comment
https://forums.phpfreaks.com/topic/244382-check-if-username-exist-in-datebase/
Share on other sites

$checkuser = mysql_query("SELECT id FROM $tbl WHERE username = ".$_POST['username']." LIMIT 1 ");

 

        if ($checkuser){

          $row =  mysql_num_rows($checkuser);

            print 'username exist.';

 

        }

should it be something like this ?

$checkuser = mysql_query("SELECT id FROM $tbl WHERE username = ".$_POST['username']." LIMIT 1 ");

        if (!empty($checkuser)){
           $row =  mysql_num_rows($checkuser);
            print 'username exist.';        
}else{
print 'username dont exist.';   
}

OR


  if ($checkuser !== ""){
           $row =  mysql_num_rows($checkuser);
            print 'username exist.';        
}else{
print 'username dont exist.';   
}

 

what's wrong ? when i click submit an username that is in the database its doesn't  print 'username exist.' and the username goes in the database ...

<?
$checkuser = mysql_query("SELECT id FROM $tbl WHERE username = '".$_POST['username']."' LIMIT 1 ");
$row =  mysql_num_rows($checkuser);

        if ($row!=0)
{ print 'username exist.';        }
else
{ print 'username dont exist.';   }
?>

Number of result is equal is zero. Print username don’t exist

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.