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

-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

Replies are listed 'Best First'.
Possible Bug?
by dru145 (Friar) on Apr 16, 2002 at 20:32 UTC
    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