zealf has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys, have a question. My below script is producing a 500 error. I an running scripts with the ole cgi.pl but now I've enhanced things with use CGI I can't get it to work.

I have debugged it and get syntax ok msg's, so guessing the script is ok.

Any ideas?

#!/usr/bin/perl use strict; use warnings; use diagnostics; use cgi qw(:standard); use CGI::Carp 'fatalsToBrowser'; $CGI::POST_MAX=1024 * 100; # max 100K posts my $query = CGI->new(); my @names = $query->param; foreach my $name ( @names ) { my $value = $query->param( $name ); } my $organisers_name=('organisers_name'); my $organisers_address=('organisers_address'); my $organisers_homeN=('organisers_homeN'); my $organisers_mobile=('organisers_mobile'); my $organisers_email=('organisers_email'); my $prefered_contact=('prefered_contact'); my $brides_name=('brides_name'); my $brides_number=('brides_number'); my $wedding_date=('wedding_date'); my $bride_organiser=('bride_organiser'); my $suprise=('suprise'); print <<print_tag; <html> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http:/ +/www.w3.org/TR/html4/loose.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" > <title>$organisers_name Hens party with The Man in the Charcoal Suit b +ooking page</title> <link rel="stylesheet" type="text/css" href="../web_layout.css" > </head> <body onLoad="MM_preloadImages('buttons/list-off.jpg','buttons/list-on +.jpg','buttons/list-active.jpg')"> <div id="everything1"> <div id="top_text"> </div> <div id="left"> <div id="navcontainer"> <ul id="navlist"> <li><a href="../index.html"><img src="../images/Logo_p +ic.jpg" width="70" height="176" border="0"></a></li> <br> <li><a><img src="../images/icons/bookings.jpg" width=" +70" height="70" border="0" hspace="0"></a></li> <li><a href="../bookings.html">Booking office</a></li> <br> <li><a href="../comments.html"><img src="../images/ico +ns/comments.jpg" width="70" height="70" border="0" hspace="0"></a></l +i> <li><a href="../comments.html">Testimonials</a></li> <br> <li><a href="../contact.html"><img src="../images/icon +s/contact.jpg" width="70" height="70" border="0" hspace="0"></a></li> <li><a href="../contact.html">Contact Us</a></li> </ul> </div> </div> <div id="side_pic"></div> <div id="main1"> <img src="../images/booking_steps/step1.jpg" align="right"> <br> <p1><b1>So far so Good.</b1><br> <p1>Below lists the details that you have entered so far. <br> <b1>PLEASE CHECK THESE CAREFULLY</b1> <br> <p1>If everything is ok click the "proceed" button or the "return" + button to correct anything.<p1> <br> <br> <form method="post" action="bookings2.cgi"> <hr> <h1>Your details</h1> <p1>$organisers_name<br> <p1>$organisers_address<br> <p1>$organisers_homeN<br> <p1>$organisers_mobile<br> <p1>$organisers_email<br> <p1>How do you preferr to be contacted $prefered_contact<br> <br> <hr> <h1>The Bride to be's details</h1> <p1>$brides_name<br> <p1>$brides_number<br> <p1>The date of the wedding? $wedding_date<br> <p1>Is the Bride organising this party? $bride_organiser<br> <p1>Is this a suprise party for the Bride? $suprise<br> <hr> <INPUT TYPE="hidden" NAME="organisers_name" VALUE="$organisers_nam +e"> <INPUT TYPE="hidden" NAME="organisers_address" VALUE="$organisers_ +address"> <INPUT TYPE="hidden" NAME="organisers_homeN" VALUE="$organisers_ho +meN"> <INPUT TYPE="hidden" NAME="organisers_mobile" VALUE="$organisers_m +obile"> <INPUT TYPE="hidden" NAME="organisers_email" VALUE="$organisers_em +ail"> <INPUT TYPE="hidden" NAME="prefered_contact" VALUE="$prefered_cont +act"> <INPUT TYPE="hidden" NAME="brides_name" VALUE="$brides_name"> <INPUT TYPE="hidden" NAME="brides_number" VALUE="$brides_number"> <INPUT TYPE="hidden" NAME="wedding_date" VALUE="$wedding_date"> <INPUT TYPE="hidden" NAME="bride_organiser" VALUE="$bride_organise +r"> <INPUT TYPE="hidden" NAME="suprise" VALUE="suprise"> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return t +rue;"> <INPUT type="submit" value="Proceed to Step 2"> </FORM> </div> </div> </body> </html> print_tag

Replies are listed 'Best First'.
Re: Server 500
by marto (Cardinal) on Apr 27, 2010 at 13:28 UTC
Re: Server 500
by moritz (Cardinal) on Apr 27, 2010 at 13:28 UTC
Re: Server 500
by wfsp (Abbot) on Apr 27, 2010 at 13:47 UTC
    foreach my $name ( @names ) { my $value = $query->param( $name ); } my $organisers_name=('organisers_name'); ...
    Not sure what you are trying to there, but something like
    my %param_hash = $query->Vars; # later, perhaps after some validation <p1>$param_hash{organisers_name}<br>
    might be worth considering. I haven't seen a <p1> tag before, is that a typo?

    And, as others have suggested, keep an eye on the error logs.

    updated: gave the param_hash the correct sigil

    updated 2: You are missing the print $q->header; line too. That could be the cause of your 500 error.

Re: Server 500
by Old_Gray_Bear (Bishop) on Apr 27, 2010 at 14:08 UTC
    A quick check with Google turn up this:
    The Web server (running the Web Site) encountered an unexpected condition that prevented it from fulfilling the request by the client (e.g. your Web browser or our CheckUpDown robot) for access to the requested URL.

    This is a 'catch-all' error generated by the Web server. Basically something has gone wrong, but the server can not be more specific about the error condition in its response to the client. In addition to the 500 error notified back to the client, the Web server should generate some kind of internal error log which gives more details of what went wrong. It is up to the operators of the Web server site to locate and analyse these logs.

    This is a long way of saying that the problem is not with your code, dear Brutus, but with in your Server. (My apologies to Bill Shakespeare, but it is waaaay before coffee.)

    ----
    I Go Back to Sleep, Now.

    OGB

      Actually, in usually *is* the fault of your code. 500 is the servers way of saying "I didn't do it and I'm ok". If something goes wrong and the server knows what, it'll be more specific than returning a 500. But if it calls program, and the program dies (be it because it cannot be compiled, exits unexpectedly, doesn't generate any output, something else), then the server throws you a 500. It usually doesn't know what happened, and if it would know, it wouldn't tell you.
Re: Server 500
by technojosh (Priest) on Apr 27, 2010 at 14:36 UTC
    Try adding the line:
    print header(-type=>'text/html');
    before:
    print <<print_tag;