Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: DBI script runs from command line, not from CGI

by dru145 (Friar)
on Apr 16, 2002 at 16:16 UTC ( [id://159550]=note: print w/replies, xml ) Need Help??


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

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.
  • Comment on Re: Re: DBI script runs from command line, not from CGI

Replies are listed 'Best First'.
Re: Re: Re: DBI script runs from command line, not from CGI
by tachyon (Chancellor) on Apr 16, 2002 at 16:36 UTC
    -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.

        No bug, just a simple coding error :-) If you used better varnames than $i and $j it would be more obvious. Just a thought.

        for $i (keys %data) { push (@ips, $i); for $j (keys %{$data{$i}{ports}}) { # push (@names, $data{$i}{cname}); # <--wrong push (@names, $data{$i}{$j}{cname}); } } # compare that with this code that uses logical names # if also uses my to localise variable scope, strict compliant too for my $ip (keys %data) { push @ips, $ip; for my $port ( keys %{$data{$ip}->{ports}} ) { push @names, $data{$ip}->{$port}->{cname}; } }

        I recommend that you add this code to check your data structure after you build %data from the file (if you were using CGI::Simple you could just call the dump() method :-) but anyway:

        # make %data require Data::Dumper; print $q->header; print $q->escapeHTML(Dumper(\%data)); exit;

        This will tell you if you have the correct data structure. I will tell you now with your current code you won't. I suspect there may be some serious logic errors in it. If you post a sample of the file I'll give you a hand to parse it into a logical data structure.

        tachyon

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://159550]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found