Premature end of script headers

M

madan

hi all,
i am getting the error "Premature end of script headers" when ever i
include use Win32::ODBC.
i need to connect to database...
my code is as below..
#! /usr/bin/perl

push(@INC,"/cgi-bin");
require("cgi-lib.pl");
require("CGI.pm");

$query=new CGI;
print &PrintHeader;
print $query->start_html;
print $query->startform("get","/cgi-bin/data.cgi");

use Win32::ODBC;

$dbh= new Win32::ODBC("dsn=madan; uid=madan; pwd=madan");

print "<input type=text name=dsn value=$dsn><br>";
print "<center>The List of Tables That are specified in the DataBase
you Entered are:<br>";

if(!$dbh)
{
print "failure in connecting ".Win32::ODBC::Error();
exit();
}
else
{
print "Connection Sucessful<br>";
}
$dbh->Connection();

foreach $Temp ($dbh->TableList())
{
$Table = $Temp;
print "<option value=$Table>$Table";
}
print "</select><br><br>";
print "<br><br><input type=submit value=Submit>";
print $query->endform;
print $query->end_html

thanks in advance
madan chowdary
Edit/Delete Message
 
J

John Bokma

madan said:
hi all,
i am getting the error "Premature end of script headers" when ever i
include use Win32::ODBC.
i need to connect to database...
my code is as below..

Do yourself a favour, and throw away the book you have been using. Or
better, burn it, it should not fall into the hands of someone else.
#! /usr/bin/perl

push(@INC,"/cgi-bin");

You might want to use

use lib '/cgi-bin';

moreover, are you sure that your cgi-bin is under the root (not as in
Document Root, where it *shouldn't* be IMO).
require("cgi-lib.pl");

Sounds like a very, very outdated CGI library to me, which you probably
don't want to use.
require("CGI.pm");

use strict;
use warnings;

use CGI::Carp 'fatalsToBrowser';
use CGI;
$query=new CGI;

better:

my $cgi = CGI->new;
print &PrintHeader;

You really need the & there? (I don't think so). Use:

print $cgi->header( 'text/html' );
print $query->start_html;
print $query->startform("get","/cgi-bin/data.cgi");

See, and that's why I recommend $cgi, since it's silly to let a query
start html.
use Win32::ODBC;

Better move this up, probably best place is just after use CGI;
$dbh= new Win32::ODBC("dsn=madan; uid=madan; pwd=madan");

print "<input type=text name=dsn value=$dsn><br>";
print "<center>The List of Tables That are specified in the DataBase
you Entered are:<br>";

if(!$dbh)
{
print "failure in connecting ".Win32::ODBC::Error();
exit();

you might want to do this earlier on, before you start an HTML page for
example.
}
else
{
print "Connection Sucessful<br>";
}
$dbh->Connection();

foreach $Temp ($dbh->TableList())
{
$Table = $Temp;
print "<option value=$Table>$Table";
}

Uhm, why a "$Temp"?

Disclaimer: typos and other errors because of 1:15 AM :-D.
 
M

madan

hello Mr.John Bokma
thanks for ur replay..but i modified the source code as u specified but
still some error is coming...
the modified program is as below

#######################################################################

#! /usr/bin/perl

use lib '/cgi-bin/lib';
require("CGI.pm");
use strict;
use warnings;

use CGI::Carp 'fatalsToBrowser';
use CGI;
use Win32::ODBC;
my $cgi = CGI->new;
$dbh= new Win32::ODBC("dsn=madan; uid=madan; pwd=madan");
if(!$dbh)
{
&printFailure;
exit();
}
else
{
&printSucess;
}
print $cgi->header( 'text/html' );
print $cgi->start_html;
print $cgi->startform("get","/cgi-bin/data.cgi");
sub printFailure {
print "failure in connecting <br>".Win32::ODBC::Error();
}
sub printSucess {
print "Connection Sucessful<br>";
}
print $cgi->endform;
print $cgi->end_html;
########################################################################

the following error is being displayed on the screen:

#######################################################################
Software error:
Undefined subroutine &Scalar::Util::blessed called at
W:/usr/lib/overload.pm line 89.
Compilation failed in require at W:/usr/lib/Config.pm line 70.
Compilation failed in require at W:/usr/site/lib/Win32/ODBC.pm line 27.
Compilation failed in require at W:/cgi-bin/dbtest.pl line 10.
BEGIN failed--compilation aborted at W:/cgi-bin/dbtest.pl line 10.
########################################################################
 
T

Tad McClellan

madan said:
Subject: hi Mr.John Bokma


Please put the subject of your article in the Subject of your article.

Your article is not about saying hi, it appears to be about
some Perl error messages.

i modified the source code


DO NOT include code if you do not understand what the code does.

If you don't know what it is _supposed_ to do, then attempting to
"fix" it will be hopeless.

require("CGI.pm");
use strict;


You should not include code if you do not understand what the code does.

Why do you (attempt to) pull the CGI module in *twice* like that?

$dbh= new Win32::ODBC("dsn=madan; uid=madan; pwd=madan");


When you include "use strict" you are making a promise to perl, if
you break your promise, perl will refuse to run your program.

You are promising to declare all of your variables, so you need
to declare all of your variables:

my $dbh= new Win32::ODBC("dsn=madan; uid=madan; pwd=madan");

if(!$dbh)
{
&printFailure;
exit();
}
else
{
&printSucess;
}
print $cgi->header( 'text/html' );


Your code guarantees that you will make some output *before*
you output the headers.

They are called "headers" because they are supposed to come
before everything else.
 
M

madan

The following error is coming only when i use Win32::ODBC module..
when i removed it the program is working fine..I checked the dsn,user
name and password all are right...
the following error is shown on the browser..

##########################################################################
Undefined subroutine &Scalar::Util::blessed called at
W:/usr/lib/overload.pm line 89.
Compilation failed in require at W:/usr/lib/Config.pm line 70.
Compilation failed in require at W:/usr/site/lib/Win32/ODBC.pm line 27.
Compilation failed in require at W:/cgi-bin/dbtest.pl line 8.
BEGIN failed--compilation aborted at W:/cgi-bin/dbtest.pl line 8.

line 8 in the pgm is :: "use Win32::ODBC;"
##########################################################################

i am new to perl...so i dont have enough stuff to write a good
syntax...
thanks in advance
 

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,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top