SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey! there,

    I am currently working on a database project which needs user registration. The problem is that the username must be unique and I thought of this code and wrote it!

    <?php if ( isset($uname) ): ?>
    <?php
    $result = mysql_query( "SELECT * FROM alumni");
    while ( $row = mysql_fetch_array($result) )

    {if ($uname == $row[uname]) {$uv = '';} else {$uv = 1;}}
    ?>

    But, the problem with this snippet is that, when I exucute, it only checks if it is the same as the last added username and exits. So, I land up having more than one similar username's.

    Can anyone help me with this ?


  2. #2
    SitePoint Zealot
    Join Date
    Nov 1999
    Location
    Manhattan!
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An easiere way is to simply search for the username in your table of users and then check if a record is returned, i.e.

    $sql = "SELECT id from users where uname=$uname";
    $result = mysql_query($sql);

    if(mysql_num_rows($result)) {
    # the username is taken
    }
    else {
    # the username is not taken
    }

    Christian


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
  •