38 users online (2 members and 36 guests)  


  Results 1 to 3 of 3

Related

  1. Replies: 2
  2. I will buy your income producing website    Forum: Websites For Sale
    Replies: 0
  3. Feedback desired    Forum: Show it off!
    Replies: 6
  1. #1
    mpriest88's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    10

    SQL Not Producing Desired Results

    I'm trying to use an SQL statement to check the email address entered on a form against the email address loaded in the database. If the email address is found I want it produce a list of first names. I'm not getting any error pages nor are there any errors in the Apache Error Log. It's simply isn't producing the list of names. Could someone please take a look at what I have so far and see what I'm doing wrong? Here's the entire Login.cgi file:

    Code:
    #!/perl/bin/perl
    
    use CGI qw(:standard);
    use CGI::Carp qw(fatalsToBrowser);
    use DBI;
    use Time::Local
    
    print header; 
    
    # Page title on top of webpage
    print start_html("Client Login");
    
    #Loops through all fields and lists them on the webpage (This is just for testing purposes)
    my %form;
    foreach my $p (param()) {$form{$p} = param($p); print "$p = $form{$p}<br>\n";}
    
    #Gets values off the form
    $ClientEmail = param("ClientEmail");
    $ClientPassword = param("ClientPassword");
    
    #Connects to the database
    my $DSN = 'driver=Microsoft Access Driver (*.mdb);dbq=C:\Documents and Settings\Mike\My Documents\My Website\Clients.mdb';
    my $dbh = DBI->connect("DBI:ODBC:$DSN") 
    or die "$DBI::errstr\n"; 
    $::db_host = 'localhost';
    $::db_name = 'Clients.mdb';
    $::db_user = 'root';
    
    #The SQL that I want to run
    my($ClientEmail, $ClientPassword, $ClientIDNbr, $ClientFName); 
    
    # 1st, get the ClientIDNbr for the ClientEmail
    my $sth = $dbh->prepare("SELECT ClientIDNbr FROM tblClients WHERE ClientEmail = '$ClientEmail'")
                    or die "prepare failed: " . $dbh->errstr(); 
    $sth->execute() or die "execute failed: " . $sth->errstr(); 
    ($ClientIDNbr) = $sth->fetchrow(); 
    
    # This line keeps causing an error ---- Fix it later
    # die "ClientIDNbr not found" unless defined $ClientIDNbr;
    
    # 2nd, for each ClientIDNbr, grab the ClientPassword and print it
    while (($ClientIDNbr) = $sth->fetchrow()) {
    	my $sth = $dbh->prepare("SELECT ClientFName FROM tblClients WHERE ClientIDNbr =  $ClientIDNbr")
    	or die "prepare failed: " . $dbh->errstr(); 
    	$sth->execute() or die "execute failed: " . $sth->errstr(); 
    	my($ClientFName) = $sth->fetchrow();
    	print "               $ClientPassword\n"; 
    	$sth->finish();
    } 
    
    $sth->finish();
    
    $dbh->disconnect(); 
    
    #End page
    print end_html;
    Thanks in advance for any and all suggestions and help
    Mike
    Last edited by vinyl-junkie; 09-10-2008 at 07:09 AM. Reason: Added code tags

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: SQL Not Producing Desired Results

    I am not certain what the issue is, but it sounds like the query is simply returning no results. Try using a shorter string for the email and change the query to:

    Code:
    SELECT ClientIDNbr FROM tblClients WHERE ClientEmail LIKE '%$ClientEmail%'"

  3. #3
    mpriest88's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    10

    Re: SQL Not Producing Desired Results

    I changed the fields names to shorten them in the database, the form and the SQL and tried your suggestion, but it still returned an empty page. Is there anything else you think I can try? I am completely stumped. Thanks for your help

    Mike



Tags for this Thread