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

Hiya. I'm new here, and I'm a just staring rogrammer (14 years from Holland :)). Anyway, I'm stuck up with a problem. My guestbook doesn't show up, in fact, it gives a 500 error. Runned on localhost, nothing working, runned on my server (and executed), no luck either. My OS is Win98 and the server's is Linux, so no chmod probs.

Maybe you could try this? I made a simple script, only printing text to see if it works, but it doesn't. Other scripts do, however. On that script (just the printing one), I changed to Perl interpreter path, but....

#!usr/bin/perl -w use warnings; # use Module warnings (for better error checking) use CGI; # use Module CGI (enhanced CGI functions) use strict; # stricter acces for subs, references and vars without sco +pe (nice for error trapping) use Fcntl; # Module used for system operations (mostly UNIX). This is +one I need for flock() use vars qw($q); print "Content-type: text/html\n\n"; # To let the CGI Interface run, d +eclare content-type # SET VARIABLES !!! # $use_flock = 0; # set to 0 if you don't use flock(), otherwise use 1 $q = new CGI; # Parameters: (we will let CGI.PM handle form-processing) my $query_name = $q->param('name'); my $query_email = $q->param('email'); my $query_msg = $q->param('message'); # prepare file acces mkdir('messages', 0777); # make directory called message, permissions +set to ALL ACCES # CALL SUBROUTINES # &open_file; &write_file; # END CALL SUBROUTINES # sub open_file { my (@filecontents); opendir(MSGDIR, "/messages"); @files = readdir(MSGDIR); close(MSGDIR); foreach $file (@files) { open(OPENFILE, "/messages/$file"); if ($use_flock == 1) { flock(OPENFILE, LOCK_NB); } # use flock() when value set to 1 @filecontents = <OPENFILE>; if ($use_flock == 1) { flock(OPENFILE, LOCK_UN); } # don't use flock() when value set to 0 close(OPENFILE); print<<__HTML__; foreach $fcontent (@filecontents) { print($fcontent); } __HTML__ } } # end open_file sub write_file { &HTML; my ($writefile) = "msg" . $$ . ".txt"; # construct filename; $ +$ = process ID if (defined($query_name, $query_email, $query_message)) { $def = 1; } else { $def = 0; } if ($def == 1) { open(WRITEFILE, ">$writefile") or die("Can't open $writef +ile. \n Error:\n $!"); print WRITEFILE, $query_name; print WRITEFILE, $query_email; print WRITEFILE, $query_msg; close(WRITEFILE); } else { print("You did not enter any valid input.\n Pleas +e go back to fill them in."); } } # end write_file sub HTML { print<<HTML; <html> <head> <title>Guestbook - Test #0.01 - Beta 0.01</title> </head> <body> <center> <font face="Tahoma"> Please fill in a messsage.<Br><br><br><br> <form method="POST"> <b>Name:</b> <input type="text" value="name"><br> <b>Email:</b> <input type="text" value="email"><br><br> <b>Message:</b> <Br><br><textarea rows="5" cols="25"></textarea><br> <Br><button type="submit">Send Message!</button> </form> </font> <center> </body> </html> HTML; } 1;

Edit by tye, remove PRE tags, add CODE and READMORE tags.

Replies are listed 'Best First'.
Re: Guestbook Problem - 500 Error [ISE]
by DamnDirtyApe (Curate) on Nov 27, 2002 at 22:17 UTC

    Well, for starters, you need to address the syntactic errors in your code. When you're using strict, all the initial declarations of your variables need to start with my, eg. my $use_flock = 0;. Run your script with the -c argument to check for errors without actually executing the code, eg. perl -c guestbook.pl. If you don't understand the errors you get, use diagnostics will provide much more verbose error messages.


    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: Guestbook Problem - 500 Error [ISE]
by davorg (Chancellor) on Nov 27, 2002 at 22:27 UTC

    If you get a 500 error in your browser then the real error message will be in the web server error log. Why not take a look in there.

    And please learn to format your posts properly.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Guestbook Problem - 500 Error [ISE]
by bart (Canon) on Nov 28, 2002 at 02:44 UTC
    I'll give you some help, just enough to make it ocompile (without strict). Please take the appropriate measures to declare all variables until strict no longer complains.

    Obvious errors:

    • The end-of-here-doc marker must be identical to what's after the "<<". Your "__HTML__" should align to the far left of the script, and there shouldn't be a semi-colon after the "HTML" near the bottom. After all, a delimiter specified without quotes, can only be a bareword.
    • The line with the multiple arguments for defined(). I think I'd make it
      if (defined($query_name) && defined($query_email) && defined($query_me +ssage)) {
      to begin with, but I'm still not sure it'll do what you want. Testing for a minimal length of at least one non-whitespace character, for example using /\S/, seems like a proper sanity check to me. Oh, on that same line, you use the variable $query_message while further up, you're using $query_msg. See, that's one thing strict is good at, flagging which variables you used.
    • Remove the commas after the "WRITEFILE" in the three print statements.
    I think that's about it. I still haven't run it, but at least I got it to compile (without strict), using "perl -wc script.pl".
Re: Guestbook Problem - 500 Error [ISE]
by arrow (Friar) on Nov 28, 2002 at 01:19 UTC
    Also, you might want to use use CGI::Carp qw(fatalsToBrowser);. It's good that you use strict and CGI.pm, but from what I understood from you question, you should be trying the simpler things (i.e. changing the perl interpreter path and setting permissions).

    Cheers