SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A Membership System Problem

    Hi all,

    I'm running a membership based website where people can register to have access to our members area.

    The problem with the script that I have is that it's "case sensitive". What I mean by that is for example:

    If I have a member in the database with username "bob", and a new member tries to signup with "Bob", they don't receive an error message! This has caused many problems so far. I don't want two members with the same username.

    Here is the script I use to register members:

    PHP Code:
    <?
    include 'db.php';

    // Define post fields into simple variables
    $firstname $_POST['firstname'];
    $lastname $_POST['lastname'];
    $emailaddress $_POST['emailaddress'];
    $username $_POST['username'];
    $country $_POST['country'];
    $how_hear $_POST['how_hear'];

    if((!
    $firstname) || (!$lastname) || (!$emailaddress) || (!$username) || 
    (!
    $country)){
        echo 
    'You did not submit the following required information!
    <br />'
    ;
        if(!
    $firstname){
            echo 
    "First Name is a required field. <br />";
        }
        if(!
    $lastname){
            echo 
    "Last Name is a required field. <br />";
        }
        if(!
    $emailaddress){
            echo 
    "Email Address is a required field. <br />";
        }
        if(!
    $username){
            echo 
    "Desired Username is a required field. <br />";
        }
        if(!
    $country){
                echo 
    "Country is a required field. <br />";
            }

        
    ?> <a href="signup.php">Click here to go back to the form</a>
    <?

    /* End the error checking and if everything is ok, we'll move on to
    creating the user account */
    exit(); // if the error checking has failed, we'll exit the script!
    }

    /* Let's do some checking and ensure that the user's username does not exist in the database */

    $sql_username_check mysql_query("SELECT username FROM users WHERE username='$username'");

    $username_check mysql_num_rows($sql_username_check);

    if(
    $username_check 0){
              echo 
    "The username you have selected has already been used
    by another member in our database. Please choose a different Username!
    <br />"
    ;
    ?> <a href="signup.php">Click here to go back to the form</a> <?
    exit();
    }
    And it goes on to insert the data into the Table, etc...

    As you can see, the script DOES check to see if there is more than one person with the picked username!

    Is there a way around this?

    Thanks. I appreciate any help.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    UK
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'" );

    replace with:-

    $sql_username_check = mysql_query("SELECT username FROM users LIKE username='".$username."'" );

    i'm pretty sure that is the correct function, it will change your string so that if it is lower or higher case it will catch it.

    I have not tested it mind you =\

    Also you could have it when you add the column to mysql you use
    strtolower($string)
    then use it while checking for existing accounts

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to try getting the value from the mysql statement, and doing:
    PHP Code:
    if ($username == $row['username'])
         echo 
    'match'
    PHP's $var1 == $var2 is case-sensitive.

    EDIT:
    Forget that, i thought you were looking for the other way around, oops.
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  4. #4
    SitePoint Member cybersunil's Avatar
    Join Date
    Apr 2003
    Location
    Mumbai
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    you might even try converting the username to lower case while the user tries to insert his name in the database and then using mysql trying finding a match or display error.

    Sunil
    Take it easy and life will take you places

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you all for your help.

    I used the strtolower($username) and it seems to be working well now.

    Thanks

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ljubljana, Slovenia
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimmy2003
    Thank you all for your help.

    I used the strtolower($username) and it seems to be working well now.

    Thanks
    what If I wanted to have username R4v3L3jCh ??? will you convert my chars into lower ?? that would annoy me ..

    just consider other options as well

    bye
    Armando

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    UK
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by armandoxxx
    what If I wanted to have username R4v3L3jCh ??? will you convert my chars into lower ?? that would annoy me ..

    just consider other options as well

    bye
    Armando
    Thats why i showed the mysql command including the LIKE instead of =

    oops, i gave you the wrong code....

    $sql_username_check = mysql_query("SELECT username FROM users WHERE username LIKE '".$username."'" );

    oops sorry


Bookmarks

Posting Permissions

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