I am working on a rating script for my website and when I tested it just now it killed my cgi-bin scripts. I looked over the code and think I figured out what was going wrong but I want to post here and get some input before I break the server again. Orignal code:
#!/user/perl/ use CGI q~:standar~; use CGI::Carp qw(fatalsToBrowser); use strict; use DBI print "Content-type: text/html\n\n"; my ($dbh, $sth, $filename, @votes, $average, $i); $filename = $ENV{'QUERY_STRING'}; $dbh = DBI -> connect ('dbi:ODBC:', '', '') or die $DBI::errstr; $sth = $dbh -> prepare (qq~select One, Two, Three, Four, Five from Fan +Ratings where Title = ?~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; @votes = $sth -> fetchrow_array; $average = ((1 * $votes[0]) + (2 * $votes[1]) + (3 * $votes[2]) + (4 * + $votes[3]) + (5 * $votes[4])) / 5; $i = 1; while ($i <= $average) { print qq~<img src="http://www.ffinfo.com/images/misc/starfull.gif" + width="15" height="15" alt="Full Star" style="vertical-align: bottom +" /> ~; $i++ } if ($average =~ /\d\.\d/) { print qq~<img src="http://www.ffinfo.com/images/misc/starhalf.gif" + width="15" height="15" alt="Half Full Star" style="vertical-align: b +ottom" />~; } while ($i <= 5) { print qq~<img src="http://www.ffinfo.com/images/misc/starempty.gif +" width="15" height"15" alt="Empty Star" style="vertical-align: botto +m" /> ~; $i++ } $dbh -> disconnect();
What i think will fix the problem:
#!/user/perl/ use CGI q~:standar~; use CGI::Carp qw(fatalsToBrowser); use strict; use DBI print "Content-type: text/html\n\n"; my ($dbh, $sth, $filename, @votes, $average, $i); $filename = $ENV{'QUERY_STRING'}; $dbh = DBI -> connect ('dbi:ODBC:FFmisc', 'Eaglef93', 'garnet0114') or + die $DBI::errstr; $sth = $dbh -> prepare (qq~select One, Two, Three, Four, Five from Fan +Ratings where Title = ?~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; @votes = $sth -> fetchrow_array; if (defined $votes[0]) { $average = ((1 * $votes[0]) + (2 * $votes[1]) + (3 * $votes[2]) + +(4 * $votes[3]) + (5 * $votes[4])) / 5; $i = 0; while ($i <= $average) { print qq~<img src="http://www.ffinfo.com/images/misc/starfull. +gif" width="15" height="15" alt="Full Star" style="vertical-align: bo +ttom" /> ~; $i++ } if ($average =~ /\d\.\d/) { print qq~<img src="http://www.ffinfo.com/images/misc/starhalf. +gif" width="15" height="15" alt="Half Full Star" style="vertical-alig +n: bottom" />~; } while ($i <= 5) { print qq~<img src="http://www.ffinfo.com/images/misc/starempty +.gif" width="15" height"15" alt="Empty Star" style="vertical-align: b +ottom" /> ~; $i++ } } else { print qq~Be the first to rate this Fan Creation.~; } $dbh -> disconnect();
Any input on what might be breaking the server, or just a better way to do something in my script would be apreaciated (by both me and my hosting provide lol )

In reply to Sciprt killing my server by Eagle_f90

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.