#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Piscataway, NJ, USA
    Posts
    10
    Rep Power
    0
    I'm trying to use MySQL to do the following.. After a person submits a form with one of the fields being "username".. I want the Perl script to check my database for the username, if it doesn't exist, it should add. if it doesn't exist it should give an error message... i have an idea how this should work

    because of my limited SQL syntax knoweledge this is the solution that seems most viable right now, is ther a better one?

    1. as person submits form, the script should check the database using something liike "SELECT username FROM blah WHERE username = '$username'" .. then script will print out (or attempt to print out) the username column and assign that to a variable ($returnedUsername for example)..

    then maybe use something like:
    if (!$returnedUsername) {
    you have entered the following fields, etc. etc. click submit to complete registration process.
    ## this then would lead to other script which adds previously entered data to database.
    }
    else { that username exists.. please try another one..
    }

    what im looking for is a simpler solution and perhaps one that doesn't utilize two scripts. so a script which checks the availabilty of username in the database and then if that something already exists it prompts you to choose another username. otherwise, it adds your chosen username to the database.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    6
    Rep Power
    0
    I don't understand why you need to use two different scripts.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
    $dbh = &databaseConnection( $databaseDetails ) ;
    $username = $cgi->param('username') ;

    if ( $username ne '' )
    {
    $sth = $dbh->prepare("SELECT username FROM usertable WHERE username = ?") ;

    $sth->execute($username) ;
    $rows = $sth->fetchall_arrayref ;
    $sth->finish ;

    # rows is now an 'grid' reference ( a two dimensional array ref )

    if ( !defined( $rows->[0] ) &#0124; &#0124; !defined( $rows->[0][0] ) &#0124; &#0124; $rows->[0][0] ne $username )
    {
    # Call the code that generates the
    # 'username added' page
    &userNameAvailablePage() ;
    }
    }
    else
    {
    # If the username is defined, then the username is taken
    if ( $username )
    {
    $error = "Username already taken - try anothern" ;
    }
    else
    {
    $error = "Please choose a usernamen" ;
    }

    &chooseUsernamePage() ;
    }
    [/quote]

IMN logo majestic logo threadwatch logo seochat tools logo