debugging the web application

N

Nachiketh

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:mysql:sample','root','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);
 
G

Gunnar Hjalmarsson

Nachiketh said:
once i tried viewing the output in a browser.. i was shown an error
page... which said.. premature ending of script headers..

perl script:
#!usr/bin/perl

Shall probably be:

#!/usr/bin/perl
------^

If that doesn't help, try to also add this line:

use CGI::Carp 'fatalsToBrowser';
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top