|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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] ) | | !defined( $rows->[0][0] ) | | $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] |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Perl DBI MySQL question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|