I have a Perl cgi script which works perfectly when run in a dos prompt, it connects to a database on my laptop and inserts a record. But when I use the internet browser to run the script it doesn't insert the record in the database or display any messages past the following line.
$dbh=DBI->connect("DBI:Oracle:testdb",'alan', 'alan');
I have supplied the whole script below
As you can see, it takes input from a previous web page and should insert the input straight into the database, it does on dos, running the command perl history.cgi
Expand|Select|Wrap|Line Numbers
- #!c:\perl\bin\perl -w
- ####################################################
- # This procedure is used Add new notes ###
- # Alan Taylor Feb 06 ###
- ####################################################
- use CGI;
- use CGI::Carp;
- use DBI;
- $query = new CGI;
- print $query->header;
- print $query->start_html;
- $h1=$query -> param ("heading");
- $note=$query->param('note');
- # ($note = $note) =~ s/\n/\n<BR>/g;
- # $selected=$query->param ("B1");
- $h1="test";$note="test heading"; # used to forced input when testing in dos
- # Check for Blank Entry
- if ( $h1 eq "" || $note eq "" ) {
- print <<EOF;
- <html>
- <head>
- <meta http-equiv="Content-Language" content="en-gb">
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
- <title>Error</title>
- </head>
- <body>
- <p align="center"><b><font size="6" color="#FF0000">Error</font></b></p>
- <p align="center"><b>Invalid Entry</b></p>
- <p align="center"><font color="#000080">Please note you can not enter a null
- heading or note</font></p>
- <form action="http://localhost/addnewnotetodatabase.htm" method="GET" >
- <p align="center"><input type="submit" value="Re-Enter Data" name="B3"></p>
- </form>
- <p align="center"> </p>
- </body>
- </html>
- EOF
- }
- open (OUTPUT, ">c:/Inetpub/web/data.txt");
- print OUTPUT ($h1);print OUTPUT ("alankingtaylor"); # crazy name :-)
- print OUTPUT ($note);print OUTPUT ("alankingtaylor");
- close (OUTPUT);
- # Set Vars
- open FH, "<c:/Inetpub/web/data.txt" or die "Unable to open data.txt: $!";
- $in=<FH>;
- my ($title,$note) = split (/alankingtaylor/, $in);
- close FH;
- print $title;print $note;
- # Connect to Database
- $dbh=DBI->connect("DBI:Oracle:testdb",'alan', 'alan');
- $sth = $dbh->prepare_cached("INSERT INTO alan.notes (title,note) VALUES ('$title','$note')");
- $sth->execute();
- print "done";
- print $query->end_html;