Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default [PHP] Checking for username existance?

    What is the best way to check to see if a username exists?

    I use:

    PHP Code:
    $user_check mysql_query("SELECT username FROM users WHERE username='$r_username'"); 
    $do_user_check mysql_num_rows($user_check); 
     
    if(
    $do_user_check 0) { 
     die(
    'Your username is already in use. Please go <a href="register.php">back</a> and fix it.'); 

    But it always returns the "Your username is already in use" error.
    Vouches
    [x][x]

  2. #2
    Join Date
    Dec 2007
    Location
    Manchester
    Posts
    2,236
    Tokens
    118
    Habbo
    hamheyelliot

    Latest Awards:

    Default

    I've absolutely no clue, but if the number on the 3rd line of that code is '0', doesn't that mean that if there are no instances of the username, it will give the error you specified?

    But when push comes to shove, I truly have no idea.
    Last edited by hamheyelliot; 14-02-2009 at 08:51 PM.

  3. #3
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    PHP Code:
    $userQ mysql_query("SELECT * FROM `users` WHERE `username`= '$r_username'"); 
    $userC mysql_num_rows($userQ); 
     
    if( 
    $userC ) { 
         die(
    'Your username is already in use. Please go <a href="register.php">back</a> and fix it.'); 



    www.fragme.co = a project.

  4. #4
    Join Date
    Jul 2004
    Location
    Scotland
    Posts
    17,702
    Tokens
    60,948
    Habbo
    Habbic

    Latest Awards:

    Default

    Code:
    $find_user = mysql_query("SELECT username FROM users WHERE username='$r_username'");
    if(mysql_num_rows($find_user)) 
     { 
     die('Your username is already in use. Please go <a href="register.php">back</a> and fix it.'); 
     }

  5. #5
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Entrance that won't work ...feel free to correct me if i'm wrong... but it would always die on that message because using an if statement like that basically means:

    if the mysql_num_rows function works and returns true then do this:

    and not

    if the username exists in the database then do this.

    Sorry if I am incorrect
    Last edited by Source; 14-02-2009 at 09:19 PM.


    www.fragme.co = a project.

  6. #6
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    And with yours i would do a double = mark, so it will be

    PHP Code:
    $userQ mysql_query("SELECT * FROM `users` WHERE `username`= '$r_username'"); 
    $userC mysql_num_rows($userQ); 
     
    if( 
    $userC == ) { 
         die(
    'Your username is already in use. Please go <a href="register.php">back</a> and fix it.'); 


  7. #7
    Join Date
    Jul 2004
    Location
    Scotland
    Posts
    17,702
    Tokens
    60,948
    Habbo
    Habbic

    Latest Awards:

    Default

    mm i've hardly done PHP but i removed the $r_username bit and replaced it with a random one and searched a db i created when it was on it it gave the message and when it didn't showed clear page (obviously as no other code was on it)...

  8. #8
    Join Date
    Feb 2009
    Posts
    131
    Tokens
    0

    Default

    PHP Code:
    $find_user mysql_query"SELECT * FROM `players` WHERE `name` = '$bonkers'" );

    if( 
    mysql_num_rows$find_user ) == )
    {
        echo 
    "Foo' - that username is taken.";


  9. #9
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Yes blinger I believe that would be correct, my appologies I kind of rushed the response as no-one was really helping.

    Oh and calon, thanks for the wonderful block on msn considering how much I helped you. Your welcome.


    www.fragme.co = a project.

  10. #10
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    haha no problems

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •