Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am a newbie so please forgive my question that might seem simplistic. I have created a CGI script that connects to an Oracle database. When I run the script from the c prompt everything is a success. I create the database and plot it. However when I try to submit the html form that calls the script, it fails. If I comment out the section in which the script talks to the database, everything works. Here is part of the code:
my $q = new CGI; my($surname, $givenName); $ENV{REMOTE_USER} = $q->param('Login_Name'); my $room = $q->param('Room'); my $sth; my $table = SQL->new(); my $dbh= DBI->connect("dbi:Oracle:", "scott", "tiger") or die $DBI::er +rstr; if (!($dbh->selectrow_array("select * from user_tables where table_nam +e = '$table->{name}'"))){ $sth= $dbh->prepare($table->create) or die $dbh->errstr; $sth->execute or die $sth->errstr; } $sth = $dbh->prepare(q/INSERT INTO SignIn(cn, time, cdate, room) VALUE +S (?,?,?,?)/) or die $dbh->errstr; $sth->execute($ENV{REMOTE_USER}, $foo, $foo, $room); print <<ENDOFHTML $ENV{REMOTE_USER}, $time, $date, $room Content-type:text/html\n\n <html> <body> <SCRIPT language="JavaScript"> alert("$givenName $surname you have signed in successfully on $fullDat +e. Thank you and enjoy Computers 101.") </SCRIPT> </body> </html> ENDOFHTML
Here is the module that I created
package SQL; sub new{ my $self = {}; $self->{name}='SIGNIN'; bless $self; return $self; } sub create{ my $self = shift; $self->{create} = "create table SignIn (cn varchar2(64), time varc +har2(10), cdate varchar2(20), room varchar2(20))"; return $self->{create}; } sub index{ my $self = shift; $self->{index} = "create index CNIndex on self->{name}(cn)"; return $self->{index}; } 1;
Thanks for any help

Replies are listed 'Best First'.
Re: connect to Oracle through CGI
by OM_Zen (Scribe) on Jan 03, 2003 at 18:47 UTC
    Hi , The Oracle Environment Parameters are not set from with in the CGI when called from HTML , I guess and hence get those Oracle env parameters in a file and require "./oraenv.pl"; in your CGI . This may help recognize the Oracle env. Also see the error message in web server log. Regards , Padmaraj K.Shankar (Pad)
Re: connect to Oracle through CGI
by Jaap (Curate) on Jan 03, 2003 at 18:37 UTC
    It helps if you post the error message too. You can probably find it in the error_log file of your webserver.
      I'm using Apache so its the usual error of:

      The server encountered an internal error or misconfiguration and was unable to complete your request

      I think it might have something to do with the permission of the oracle directory.... Please help if you can
        The *actual* message from the error_log is what everyone is looking for.