SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old September 14th, 2000, 09:00 PM
gustavopeco gustavopeco is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Piscataway, NJ, USA
Posts: 10 gustavopeco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #2  
Old September 15th, 2000, 06:36 AM
Oliver Smith Oliver Smith is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 6 Oliver Smith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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] ) | | !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]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl DBI MySQL question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway