By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

debugging the web application

P: n/a
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);
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.