For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > October 2007 > cgi script to connect to database and diaplay data in HTML throwing error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cgi script to connect to database and diaplay data in HTML throwing error
nitikamehta23@gmail.com

2007-10-20, 7:01 pm

I am new to cgi and have a query about same...
I wan to connect to database and display soem data in HTMl format.
Below is the code which i have wriiten.
DbSettings.Pets contains database information like username,pswd,Db
name.

When i run this cgi using " http://www.web.com/TEST/cgi-bin-kerb/test.cgi"
it displays " Page cannot be displayed"

Can somebody help e out with this?

Thanks,

#!/opt/bin/perl5.004
#*************************
#******* Trecs.cgi *****
#*************************
#$Log

require "DbSettings.Pets";

Sybase::DBlib::dberrhandle('error_handle
r');
Sybase::DBlib::dbmsghandle('message_hand
ler');

use CGI;

$query = new CGI;

&Main ();

$dbproc->dbclose();

sub Main {

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

&GetRegions;
&display_menu;

sub GetRegions
{

@RegionData = $dbproc->sql("SELECT CheckName FROM CheckTb");
$NumRegions = @RegionData;
}

sub display_menu {
print <<EOF;
<HTML>
<HEAD>


<TABLE>
<TR><TD><FONT COLOR="BLUE"><B>ICOLT<TD>--</B>
<TD>
CHECKNAME:
<TD><SELECT NAME=CHECKNAME>
EOF
foreach $Region (@RegionData)
{
print "<OPTION>$$Region[0]";
}
print <<EOF;
</SELECT>

</TABLE>
EOF

} #Main

#***************************************
****************************************
******
#******************** error handler
****************************************
*******
#***************************************
****************************************
******


sub error_handler
{

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

my ($db, $severity, $error, $os_error, $error_msg,
$os_error_msg) = @_;

# Check the error code to see if we should report this.
# Traps operating system level errors; much more severe than
sql related errors
# Add whatever code necessary to handle the error properly

print "Error detected:<BR>";
print "severity: $severity<BR>";
print "error: $error<BR>";
print "database: $db<BR>";
print "message: $error_msg<BR>";
print "os error msg: $os_error_msg<BR>";
INT_CANCEL;
}

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

my ($db, $message, $state, $severity, $text, $server,
$procedure, $line) = @_;
# Used to trap Sybase messages generated in cases like trying
to
# insert a row that violates an index. Currently we don't do
anything,
# add whatever code necessary to handle the message properly

print "Message detected:<BR>";
print "database: $db<BR>";
print "message: $message<BR>";
print "text: $text<BR>";
print "server: $server<BR>";
print "line no: $line<BR>n";
0;
}

Janwillem Borleffs

2007-10-20, 7:01 pm

nitikamehta23@gmail.com wrote:
> When i run this cgi using "
> http://www.web.com/TEST/cgi-bin-kerb/test.cgi" it displays " Page
> cannot be displayed"
>


The first you should check is what's in your apache error logs.

You might also want to start your scripts with the following line to get
more verbose error messages (in some cases):

use CGI::Carp qw(fatalsToBrowser);

Anyways, the error seems to be in the following snippet:

> sub Main {
>
> print "Content-type: text/html\n\n";
>
> &GetRegions;
> &display_menu;
>
> sub GetRegions
> {
>


The body of the Main sub routine isn't closed (missing closing curly
bracket).


JW


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com