I have some problem doing conditioning after retrieving results back from a db query.
What I want to do is a "if-else" , if user is found, redirect to "app.pl" else show some error messages.
any idea what's wrong?
I get a "500 Internal Server Error" message

=====
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


In reply to CGI question by slok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.