MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Robert (IMI) Date:July 6 1999 9:40pm
Subject:The correct way to compare data in a database?
View as plain text  
Looking for the most effective way to look in a table that I have and check the username
against a password.. 

The user will be using a CGI form and entering a username and a password.. the way I have
it now is it looks thru all the usernames and if it finds a match it pulls that into a
variable along with the password.. after its went thru the entire table it closes the
table and checks to see if the results match.. 

Below is the code..  I am attempting to learn the correct way to do this MySQL program
rather than just go with the first thing that works.. 

# there is a connect statement above this.. 

# Prepare the statement for execution
 $sth =
     $dbh->prepare( "
   SELECT username, password, sponsor
   FROM users
       " );
 if ( !defined $sth ) {
     die "Cannot prepare statement: $DBI::errstr\n";
 # Fetch the data 
while ( ( $username, $password, $sponsor ) = $sth->fetchrow() ) {
  if ($username eq "$FORM{'username'}") {
   $myusername = "$username";
   $mypassword = "$password";
   $mysponsor = "$sponsor";  
 # Release the statement handle resources
 # Disconnect from the database
 if ($mypassword eq "$FORM{'password'}") {
  $passed = ":";


Robert Saunders

The correct way to compare data in a database?IMI)7 Jul
Re: The correct way to compare data in a database?(David Sklar)7 Jul
RE: The correct way to compare data in a database?Darren L Sweeney7 Jul