Login Script help

Discussion in 'PHP' started by uniqueasitis, Jun 16, 2007.

  1. #1
    If you want to check for an existing username could you use a query like

    SELECT username FROM table WHERE username= \"$username_to_test\"

    and then use the following code to determine if the particular username exists or not:

    $row = mysql_fetch_array($result);
    if(!($row))
    echo $usernameexists;

    Or is there a better way?
     
    uniqueasitis, Jun 16, 2007 IP
  2. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I typically use something along the lines of:

    
    <?php
        if (mysql_num_rows($result) == 0)
        {
            echo "Username exists!";
            exit();
        }
    ?>
    
    PHP:
    Obviously thats a very stripped down version, but you get the idea.
     
    CodyRo, Jun 16, 2007 IP
  3. uniqueasitis

    uniqueasitis Peon

    Messages:
    661
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah. Good idea. Thanks
     
    uniqueasitis, Jun 17, 2007 IP