slok has asked for the wisdom of the Perl Monks concerning the following question:
=====do 'dbi-lib.pl'; use CGI ':standard'; use DBI; use strict; use vars qw($baseURL); # Declare base URL for return from this page $baseURL = "../index.html"; # print HTML header identifying document as HTML from dbi-lib.pl printHead('Logon User - Get Data'); print <<ENDOFTEXT; <H1>TDPS</h1> <br> ENDOFTEXT createform(); printclose(); # # Gather data to create HTML form ------------------------------------ +--- # sub createform { my $q = new CGI; # get values passed from form my $user = $q->param('user'); my $passwd = $q->param('passwd'); my $dbuser = 'ass2'; my $dbpasswd = 'tdps'; my $cnt; # Database DBI driver name my $dbname = "DBI:Oracle:"; # Create database handle my $dbh = DBI->connect($dbname, $dbuser, $dbpasswd); if (!$dbh) { showSQLerror("Connecting to the database"); return; } else { # set AutoCommit 1 = ON, 0 = OFF $dbh->{AutoCommit} = 1; } # Select to collect department numbers and names for pull down lis +t # on form - **ONLY** use such lists if count of rows would be smal +l # say 10 - 15 rows my $sql = "SELECT count(*) as cnt from users where USER_CODE = \'$ +user\' and PIN = \'$passwd\'"; # my $sql = "SELECT count(*) as cnt from users"; # Create a statement handle - prepare the statement my $sth = $dbh->prepare($sql); if (!$sth) { showSQLerror("Preparing SQL statement"); $dbh->disconnect; return; } # Execute the statement against the database $sth->execute; if ($DBI::errstr) { showSQLerror("Executing SQL Statment"); $sth->finish; $dbh->disconnect; return; } # Output the data fetched while (my ($cnt) = $sth->fetchrow) { if (my $cnt == 0) { print <<ENDOFTEXT; <table border=2 width=400> <tr> <td width=250><b>Count0</b></td> <td width=150>$cnt</td> </tr> ENDOFTEXT } else { print <<ENDOFTEXT; count1<p>$cnt ENDOFTEXT } print <<ENDOFTEXT; </table> ENDOFTEXT $sth->finish; $dbh->disconnect; }
Edit kudra, 2002-05-07 Added READMORE
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI question - Header Error?
by tadman (Prior) on May 07, 2002 at 07:05 UTC | |
|
Re: CGI question
by grep (Monsignor) on May 07, 2002 at 07:08 UTC | |
|
Re: CGI question
by tachyon (Chancellor) on May 07, 2002 at 15:21 UTC |