in reply to DBI script runs from command line, not from CGI

As usual when a script runs from the command line but not under CGI you have to ask yourself what is different between these two scenarios? A: Permissions. On the command line the script runs as user:you, under CGI it runs with user:nobody and different permissions.

When you say it runs from the command line but not under CGI what do you mean. Browser hangs, no output, wrong output? I have found that CGI::Carp 'fatalsToBrowser' does not catch all errors. As a result I use this in debugging:

BEGIN { $|++; # autoflush buffers; use CGI::Carp 'fatalsToBrowser'; print "Content-type: text/html\n\n"; }

This relaibly gets the errors to the browser and has the added bonus of printing whatever headers your script is sending in plaintext at the top of the window.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: DBI script runs from command line, not from CGI
by dru145 (Friar) on Apr 16, 2002 at 16:16 UTC
    tachyon,

    Thanks for the suggestion. I added those three lines to the top of my script, and still didn't get any errors. I should have said it does not run correctly under CGI. It runs, but it is not adding the data to the database. I'm just getting the display page that says the data was uploaded successfully, but it wasn't.

    I checked my permissions and they are the same as my other CGI scripts that work fine.

    Anything else I should check?

    Thanks,
    Dru
    Another satisfied monk.
      -enctype => "application/x-www-form-urlencoded"

      For file uploads to work the ENCTYPE must be "multipart/form-data". As you use start_multipart_form you don't need to specify an ENCTYPE as CGI.pm will specify it for you.

      You do no checking to see that you got your file uploaded (it does not) and that you got wrote data in %data (no file, no %data) so you have nothing to insert.

      A bit more error checking to ensure that the file arrived and that data was retieved might be in order, even though fixing the enctype should fix the problem.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        tachyon and fellow monks,

        I took out ENCTYPE, and it still did not work. I know my file arrived ok, because I tested it with this code:
        while(<$infile>){ push (@line, $_); }
        When I print out @lines, it prints out the file I just uploaded. Also, this bit of error checking seems to work
        my $infile = upload ('file') or die "File was not uploaded correctly\n +";
        because if I don't enter a filename, I get the error "File was not uploaded correctly."

        Next, I started looking at my hash. Now, here is the strange part. This code works fine:
        for $i (keys %data) { push (@ips, $i); }
        I can print out @ips in the results page, but then I tried this:
        for $i (keys %data) { push (@ips, $i); for $j (keys %{$data{$i}{ports}}) { push (@names, $data{$i}{cname}); } }
        and @names would not print out. I also tried this:
        for $i (keys %data) { for $j (keys %{$data{$i}{ports}}) { push (@ips, $i); } }
        and now @ips does not print out. I tried the last two bits of code in a non-CGI script, and they both print out as expected. Do you think I stumbled on a possible bug? I would appreciate any suggestion since this is driving me crazy.

        Thanks,
        Dru
        Another satisfied monk.