Perl Help :<

Soldato
Joined
12 Jan 2006
Posts
2,547
I have run out of ideas , basically when i run this script from the console it is fine outputs the right html.
But as soon as i run it from a browser i get errors :/
the script is essentially the same as one called Named Artist, with the only difference being the table it refers to in the database.
Now the SQL Query works
the Perl script works in the console
the HTML is identical to a working version bar refering to a different perl script

For the sake of testing i hard coded some data to test if the tables work.

Code for my html page:
Code:
<html>

<head>

<title>Select a player form</title>

</head>

<body>

<h2>Select a player form</h2>

<FORM METHOD="POST" ACTION="http://www2.wmin.ac.uk/~w0402086/cgi-bin/TotalSales.pl">

<p><h3>
Enter the name of a player to obtain their full details
</h3></p>

<center>

<p>Day
<input type="text" name="Day" size="2" maxlength="2"/>
</p>

<p>
Month<input type="text" name="Month" size="2" maxlength="2"/>
</p>

<p>
Year<input type="text" name="Year" size="2" maxlength="2"/>
</p>

<input type="submit" name="Sub" value="Send query"/>

<input type="reset" value="Reset Form"/>

<input type="hidden" name="HiddenName" value="selectform.html"/>

</center>
</form>

</body>

</html>

Code for my perl script
Purposfully left out the stuff to setup the enviroment
Code:
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
@pairs= split(/&/,$buffer);
foreach $pair (@pairs) {                    
   ($name,$value) = split(/=/,$pair);                            
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    $contents{$name} = $value;
    }
#$Day = $contents{'Day'};
#$Day =~ s/$regexp//g;   #  remove suspect chars
#$Month = $contents{'Month'};
#$Month = =~ s/$regexp//g;   #  remove suspect chars
#$Year = $contents{'Year'};
#$Year =~ s/$regexp//g;   #  remove suspect chars

$Day = '12';
$Month = '12';
$Year = '03';

my $dbh = DBI->connect("dbi:Oracle:ORA8", "username","password")
		or die "Cannot connect: " .  $DBI::errstr;
my $sql = "SELECT SaleDate /*, COUNT(*) Total_Sales*/
FROM Sales
WHERE SaleDate = to_date('$Day/$Month/$Year' ,'DD/MM/YY')
GROUP BY SaleDate";
my $sth = $dbh->prepare($sql) or die "Cannot prepare: " . $dbh->errstr();

if ($sth->execute()) {
my @data;
my $count = 0;
print "Content-Type: text/html;charset=ISO-8859-1\n\n";
print "<html>\n<head>\n<title>Recording Search</title>\n</head>\n";
print "<body bgcolor=\"peachpuff\"><h1>Artist's Recordings</h1>\n";
print "\n<TABLE BORDER=1 ALIGN=CENTER>";
print"<tr><th>Artist's Name</th></tr>\n";
while (@data =$sth->fetchrow_array())
{ ++$count;
    print "<tr bgcolor=ffddbb>\n";
    foreach my $element (@data) {
      print "<TD>$element\n</TD>";
      }
      #print"<br></br>";
      print"</TR>";
 }
   print "</TABLE>"; 
 }
 
 print "</body>\n</html>\n"; 
$sth->finish();
$dbh->disconnect();

Output in console:
Code:
58 tiger% perl TotalSales.pl
Content-Type: text/html;charset=ISO-8859-1

<html>
<head>
<title>Recording Search</title>
</head>
<body bgcolor="peachpuff"><h1>Artist's Recordings</h1>

<TABLE BORDER=1 ALIGN=CENTER><tr><th>Artist's Name</th></tr>
<tr bgcolor=ffddbb>
<TD>12-DEC-03
</TD></TR></TABLE></body>
</html>

Output when using webpage
Code:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Its not a administrative problem as all my pervious pages work fine
Any help would be much appreciated
 
Last time I had a problem like this it was html generation related. Check the server error logs, my moneys on the script is generating the html in such a way that Apache is baulking on it.

Two things to try;

1> strip all of the sql stuff out and just make sure that the html generation works. Just chop out you html statements and try them alone in a cgi script.

2> try print 'html stuff'; (single quotes) instead of print "html stuff"; (double quotes) as it will save you having to escape as many html tags as you are having to do right now.

btw you might want to have a look at constant, makes DB coding a lot easier on the eye. And can be quite handy for building in debugging handles.

use constant DBI_DSN => 'dbi:mysql:hostname=localhost;database=my_db';
use constant DBI_USR => 'db_user';
use constant DBI_PWD => 'db_password';


my $dbh = DBI->connect(DBI_DSN, DBI_USR, DBI_PWD,
{'RaiseError' => 1});
 
Checked the server log? :p

Check the webserver has execute permissions (generally 755), check it's in the cgi-bin folder, and apart from that I haven't a clue :)
 
Back
Top Bottom