Loading ...
Sorry, an error occurred while loading the content.

Guestbook script problem

Expand Messages
  • Mystik Gotan
    Hi. I m a young (14, dutch) Perl Programmer (or so however you may call, some call me, some might don t ;)). Anyway, I m getting a 500 error on my script. I
    Message 1 of 2 , Nov 27, 2002
    • 0 Attachment
      Hi.

      I'm a young (14, dutch) Perl Programmer (or so however you may call, some
      call me, some might don't ;)). Anyway, I'm getting a 500 error on my script.
      I changed some things, like print content type in subs, and I put the HTML
      form in the script. But no changes for the ISE error. Hope you guys can help
      me :-)

      ########################################################
      #!usr/bin/perl -wT

      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 scope
      (nice for error trapping)
      use Fcntl; # Module used for system operations (mostly UNIX). This is one I
      need for flock()
      use vars qw($q, $query_name, $query_email, $query_message);


      print "Content-type: text/html\n\n"; # To let the CGI Interface run, declare
      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)
      $query_name = $q->param('name');
      $query_email = $q->param('email');
      $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) {
      print "Content-type: text/html\n\n";

      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__;
      print STDIN, @filecontents; # actually, you don't need STDIN (I
      think)...
      __HTML__
      }
      } # end open_file

      sub write_file {
      print "Content-type: text/html\n\n";

      &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 $writefile. \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 Please 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;





      --------------
      Bob Erinkveld (Webmaster Insane Hosts)
      www.insane-hosts.net
      MSN: gotan2k3@...




      _________________________________________________________________
      Ontvang je Hotmail & Messenger berichten op je mobiele telefoon met Hotmail
      SMS http://www.msn.nl/jumppage/
    • Charles K. Clarkson
      ... You should try testing your scripts from the command line before running them on the server. Your program is riddle with typographical errors and
      Message 2 of 2 , Nov 27, 2002
      • 0 Attachment
        Mystik Gotan [gotan2k3@...] wrote:

        : I'm getting a 500 error on my script.
        : I changed some things, like print content type in
        : subs, and I put the HTML form in the script. But
        : no changes for the ISE error.

        You should try testing your scripts from the
        command line before running them on the server.
        Your program is riddle with typographical errors
        and undeclared variables.
        If you don't have access to the command line,
        try installing perl on your local system. You can
        check your script's syntax with the -c option on
        the command line or on the shebang (#!) line. If
        you absolutely have to run the script from a
        server try carping your fatals to the browser:

        #!/usr/local/bin/perl -T

        use CGI::Carp 'fatalsToBrowser';
        .
        .
        .


        HTH,

        Charles K. Clarkson
        --
        Head Bottle Washer,
        Clarkson Energy Homes, Inc.
        Mobile Home Specialists
        254 968-8328
      Your message has been successfully submitted and would be delivered to recipients shortly.