debugging the web application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nachiketh

    debugging the web application

    hi,
    am a newbie for internet programming and i wrote a perl script to
    acess a mysql database on linux... but once i tried viewing the output
    in a browser.. i was shown an error page... which said.. premature
    ending of script headers.. if anyone can help me debug the perl
    script...
    -Nachiketh

    perl script:
    #!usr/bin/perl
    use CGI;
    use DBI;
    $q = new CGI;
    $pnr = $q -> param('pnr');

    $dbh = DBI -> connect('DBI:my sql:sample','ro ot','soccer');
    $sql = "select * from railways where pnr_no = '$pnr'";

    $sth = $dbh -> prepare($sql)
    or die "cant prepare sql query $sql:$dbh->errstrn";

    $rv = $sth -> execute
    or die "cant execute sql query $sql:$dbh->errstrn";

    while(@result = $sth -> fetchrow())
    {
    $key = $result[0];
    $status = $result[1];
    }

    if ( $rv > 0)
    {
    if($status eq "Waiting" or $status eq "waiting")
    {
    print "Content-type: text/html","\n";
    print "Pragma: no-cache","\n\n";
    print "<HTML>\n";
    print "<BODY>\n";
    print "<H1>Your PNR number has been updated in our database and you
    are in our waiting list</H1>\n";
    print "</BODY>\n";
    print "</HTML>";
    $sth -> finish();
    # $dbh -> disconnect();
    }
    else
    {
    $sql1 = "select * from details where pnr_no='$key'";
    $sth1 = $dbh -> prepare($sql1)
    or die "Unable to prepare the Query" ;
    $rv1 = $sth1 -> execute()
    or die "Unable to execute query";
    while(@result1 = $sth1 -> fetchrow())
    {
    $pnr_no = $result1[0];
    $coach_no = $result1[1];
    $berth_no = $result1[2];
    $train_name = $result1[3];
    $train_no = $result1[4];
    $time = $result1[5];
    $date = $result1[6];
    }
    print "Content-type: text/html","\n";
    print "Pragma: no-cache","\n\n";
    print "<HTML>\n";
    print "<BODY>";
    print "<H1>Here are the details of your reservation</H1>\n";
    print "<BR>Train Name: $train_name<BR> \n";
    print "<BR>Train Number: $train_no<BR>\n ";
    print "<BR>Coach Number: $coach_no<BR>\n ";
    print "<BR>Berth Number: $berth_no<BR>\n ";
    print "<BR>Date Of Journey: $date<BR>\n";
    print "<BR>Time Of Journey: $time<BR>\n";
    print "WISH YOU A VERY HAPPY JOURNEY\n";
    print "</BODY>\n";
    print "</HTML>\n";
    $sth1 -> finish();
    $dbh -> disconnect();
    }
    }
    else
    {
    $sth -> finish();
    $dbh -> disconnect();
    print "Content-type: text/html","\n";
    print "Pragma: no-cache","\n\n";
    print "<HTML>\n";
    print "<BODY>\n";
    print "<H1>Please Enter a Valid PNR number or your PNR Number does
    not exist</H1>\n";
    print "</BODY>";
    print "</HTML>";
    }
    exit(0);
Working...