Fellow Monks,

I can get the following code to run fine from command line (without the CGI stuff), but not in this CGI script. I am not getting any errors either (to the screen or in the logs). Anyone know what I'm doing wrong?

Snippet of code from the form which asks for the filename:
start_multipart_form( { -action => "action_upload.cgi", -enctype => "application/x-www-form-urlencoded", -method => "post" } ), .............some html table code................................. Tr( { -style => "background-color:#CCCCCC" }, td( strong( "Enter the file you want to upload" ) ), td( filefield( { -name=>'file', -default=>'starting value', -size=>30, -maxlength=>80 } ) ), #end td ), #end Tr
action_upload.cgi script:
#!/usr/bin/perl -w use strict; use DBI; use CGI::Carp 'fatalsToBrowser'; use CGI qw/:standard/; my $infile = upload ('file') or die "$!"; my $message1 = "<u>The data was inserted into the database successfull +y </u>"; my ($ip,$port); my %data; do_work(); dbi(); display_page("$message1"); sub do_work { while (<$infile>){ if (/(\d+\.\d+\.\d+\.\d+)\s+(\S+)/) { $ip = $1; $data{$ip}{cname} = $2; next; } if(m/^\s{1}\|___\s+(\d+)\s\s(.*)/){ $port = $1; $data{$ip}{ports}{$port}{service} = $2; $data{$ip}{ports}{$port}{banner} = ''; next; } if(m/^\t\s{1}\|___\s+(.*)/){ $data{$ip}{ports}{$port}{banner} = $1; next; } } } sub dbi { my ($i,$j); ### Enable error checking my %attr = ( PrintError => 0, RaiseError => 1, ); ### Connect to database my $dbh = DBI->connect("DBI:mysql:audit", username, password, \%attr) +; my $sth = $dbh->prepare("insert into Supersearch (ip, svr_name, port, + service, banner) values (?,?,?,?,?)"); for $i (keys %data) { for $j (keys %{$data{$i}{ports}}) { $sth->execute($i, $data{$i}{cname}, $j, $data{$i}{ports}{$j}{s +ervice}, $data{$i}{ports}{$j}{banner}); } } ### Disconnect from db $dbh->disconnect; } sub display_page { my $message = "$_[0]"; print header, start_html( "-title" => "Results Page"), p("&nbsp;"), p( strong( $message ) ), p("&nbsp;"), end_html; }
Thanks,
Dru
Another satisfied monk.

In reply to DBI script runs from command line, not from CGI by dru145

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.