Perl Help :<

12 Jan 2006
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:


<title>Select a player form</title>



<h2>Select a player form</h2>


Enter the name of a player to obtain their full details


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

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

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

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

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

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




Code for my perl script
Purposfully left out the stuff to setup the enviroment
} 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"<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 "</TABLE>"; 
 print "</body>\n</html>\n"; 

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

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

<TABLE BORDER=1 ALIGN=CENTER><tr><th>Artist's Name</th></tr>
<tr bgcolor=ffddbb>

Output when using webpage
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
26 Oct 2002
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});
Top Bottom