I have a database connetivity problem, I have a cgi script which connects to 
the database.
I tried the CGI script at the command line and its working, it also connects 
to the database. But when I use the front end , it says there is an internal 
error , and gives the "premature end of script headers" output.
I tried to see what the problem is and zeroed down on the database 
connection string.
my database connection string is:

my $dbname='NAME';
my $dbbh= DBI->connect("dbi:Pg:dbname=$dbname", "USERNAME","PASSWD");
if (!dbh){
die "ERR :couldn't open connection:" .$DBI::errstr."\n";
}

Can you point out any error in the above and why it works at the command 
line but not at the front end. 
My script goes like this:
 I have a form where I capture the data insert this data in to a table in my 
database. I am able to capture the data and use it. when I run the script in 
the command line it works and gives me the output . But when I use the html 
form, it somehow doesn't work when there is database connetion. As long as 
there is no database connection. It returns the values of the form and all..
 I am new to all this and kind of confused.. I am posting a part of my 
script below..
This is my test script ::: I am trying to see if I can connect to database . 
I am not sure if my html embedded code is right. Any insights will be 
greatly appreciated.
 
#!/usr/bin/perl

use CGI;
use strict;
use DBI;

 my $form_data = new CGI;


my $name = $form_data->param('name');
my $number = $form_data->param('number');

my $dbname ='NAME';
my $dbh=DBI->connect("dbi:Pg:dbname=$dbname","USERNAME","PASSWD");
if (!$dbh){
die "ERR:couldn't open connection: ".$DBI::errstr."\n";
}

my $count=$dbh->selectrow_array("SELECT COUNT(*)FROM TableName");

$dbh->disconnect;

 print "Content-type: text/html\n\n";

print <<WEB_PAGE;
<!DOCTYE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/stric.dtd";>
<html>
<head>
<title> RESULT PAGE </title>
</head>
<body>
<h1> Thank you for filling out my form !</h1>
<h4> The course details are :</h4>
<p> name : $name
<p> Number: $number
<p> No of rows : $count
</body>
</html>
WEB_PAGE
exit;

 Thank you, 

Deepblues

Reply via email to