Gil Vautour said:
David K. Wall said:
I have some guesses, but without code or error messages, guesses
are all they would be.
Check the server logs and see what the error is. If you don't
have access to the server logs, put
use CGI::Carp qw(fatalsToBrowser);
in your program and try it again. That will send warnings and
error messages to the browser. If you can't figure it out from
that, post a *short* piece of code that exhibits the problem.
[snip my guess]
Well I have been using Carp but it still only produces a 500
error.
Not Carp. CGI::Carp. There *is* a difference; please be precise. Do
you mean you put the statement
use CGI::Carp qw(fatalsToBrowser);
in your program and you *still* get a 500 error?
What happens when you run it from the command line with the same
data?
I don't have direct access to the server logs, I had a sys
admin take a look for me. The only thing he could find was a
mal-formed Header problem, but it seemed like this was caused by
the script failing in general. Here is a snippet of the DBI code
that I think is where the problem occurs:
my $dbh =
DBI->connect("DBI:mysql:$database:$hostname",$user,$password)||
die "Connect failed: $dbh->errstr\n";
my($query) = @_;
my(@form,$values,$key);
foreach $key ($query->param) {
It's better to confine $key to the loop, e.g.;
foreach my $key ( $query->param ) {
I'd put $values inside the loop, too.
my $values = $query->param($key);
if ($values ne '') {
# ...
if ($query->param($key) ne "") {
^^
As a matter of style, single quotes are often preferred when there's
no variable interpolation happening.
$values = $query->param($key);
$values = $dbh->quote($values);
Hmm, the use of quote() makes my guess about placeholders wrong, as
placeholders implicitly use the quote method.
push @form,$values;
} else {
$values = "null";
push @form,$values;
}
}
my $sql = "insert into Responses
values(null,$form[0],$form[1],$form[2],$form[3],$form[4],".
"$form[5],$form[6],$form[7],$form[8],$form[9],$form[10],$form[11],$
form[12],$form[13],NOW());";
This seems to me a roundabout way of doing things. Someone please
correct me if I'm wrong, but I've generally done something like this:
# untested
my $sth = $dbh->prepare(q{
insert into Responses (colname1, colname2)
values (?,?)
})
or die $dbh->errstr;
$sth->execute( param('column1'), param('column2') )
or die $sth->errstr;
It seems odd that you never actually say which columns into which
you're inserting data, but a quick test shows that it works. I never
knew that. (and now that I know it, I don't really like it. it seems
sloppy.)
my $sth = $dbh->prepare($sql) || die "Can't prepare $sql:
$dbh->errstr\n";
my $rv = $sth->execute || die "Can't execute $sql:
$sth->errstr\n";
my $rc = $sth->finish;
$rc = $dbh->disconnect;
}
I don't see anything obviously wrong, but I've been mistaken before.
As I said above, run the program from the command line with the same
data and see what happens. It's difficult to debug something without
error and warning messages.