Results 1 to 5 of 5

Thread: [RESOLVED] user registration?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] user registration?

    i'm trying to write my website from beginning again because i want to learn programming websites so i decided to delete my old website and start with opening notepad well now i come to user registration, i realize that if i just write to the database then it will add the user even if there already is a user with that name... so i come here to ask how i can check if the username is already taken...

  2. #2
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: user registration?

    Hi,
    I still don't get it how this problem relates to your use of Notepad.

    well now i come to user registration, i realize that if i just write to the database then it will add the user even if there already is a user with that name... so i come here to ask how i can check if the username is already taken...
    Is this the problem at hand?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: user registration?

    what i mean is that i make everything from beginning the problem is i need to check if the data is already stored (username) in the database..

    edit: i think what you don't get is that i post from a php form into the database...
    Last edited by Justa Lol; Dec 4th, 2009 at 02:36 PM.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: user registration?

    your terminology is a little off -- you are not posting into a database. a form in your PHP script is POSTing (the request method) to another PHP script (or perhaps the same script sending the request), which is in turn interacting with your database.

    either way, what you need to do is query the database for any users that exist in your database with the username that is currently trying to register. a small example:

    PHP Code:
    <?php
      
    //has the form been submitted?
      
    if($_SERVER['REQUEST_METHOD'] == "POST"){
        
    //yes!

        //sanitise the username
        
    $username mysql_real_escape_string($_POST['username']);

        
    //query the database
        
    $sql "SELECT uid FROM [b]user_table[/b] WHERE username='$username'";
        
    $query mysql_query($sql);

        
    //if any results returned, this username is in use
        
    if(mysql_num_rows($query) == 0){
          
    //continue with adding the user

          //...

        
    }else{
          
    //show some sort of error or something
        
    }
      }
    ?>
    ask questions if this doesn't make sense to you.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: user registration?

    i take this back, i forgot to change uid to id..

    thanks kows i got it working
    Last edited by Justa Lol; Dec 5th, 2009 at 06:42 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width