Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

HELP WITH MY CGI PLEASE *(or maybe HTML)

Posted on 1997-07-09
2
209 Views
Last Modified: 2013-12-25
I'm having a lot of trouble getting all this to work.  Would someone
please read through it for me and give me some suggestions.  I'm just
a newbie here....

I'm trying to allow the form input to parse via the cgi and post then
to another page.  Like a guestbook actually.  It's more to be a
bulletin wall.  

I thank you in advance for any help you might offer....
dbenson@hopsgroup.com

Here's the form to send the input...
<html>
<head>
<title>Bulletin Board Submission Form</title>
</head>
<body bgcolor="#FFFBF0" text="#000000">
<p>
<center>
<form method=POST action="http://ns.netmcr.com/cgi-bin/dmanb/bull.pl">
Your Name Please: <input type=text name="usrname" size=20><br>
Your E-Mail Address: <input type=text name="email" size=17><br>
Your Comment Please: <textarea wrap="virtual" rows=7 cols=17
name="comment"></textarea><br>
<input type=submit value="Touch Me">
</center>
</body>
</html>

here's the cgi....
#!/usr/bin/perl
#This is a Bulletin Board

$bull="../../../../home/dmanb/public_html/bull/bull.htm";
$bull_url="http://ns.netmcr.com/~dmanb/bull/bull.htm";
$bull_cgi_url="http://ns.netmcr.com/cgi-bin/dmanb/bull.pl";

read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
      @pairs = split(/&/, $input);

      foreach $pair (@pairs) {
      ($name, $value) = split (/=/, $pair);

            $name=~ tr/+/ /;
            $name=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
            $value=~ tr/+/ /;
            $value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
      $FORM{$name} = $value;
      }
$usrname = $FORM{'usrname'};
$email = $FORM{'email'};
$comment = $FORM{'comment'};

$comments =~ s/<([^>]|\n)*>//g;

open(FILE, ">$bull") || die "I can't open $bull\n";

      @file = <FILE>;
      close(FILE);

      $sizefile = @file;

      open (FILE, ">$bull") || die "I can't!\n";

      for($a = 0; $a <= $sizefile;
      $sizefile++) {

      $_ = $file[$a];

      if(/<!--begin-->/) {
      print FILE "<!--begin-->\n";
      print FILE "<p><a
href=\"mailto:$FORM{'email'}\">$FORM{'usrname'}</a><br>\n";
      print FILE "$FORM{'comment'}</p>\n";
      } else {
      print $_;
}
}
close(FILE);


here's the resulting page....

<html>
<head>
<title>Bulletin Board</title>
</head>
<body bgcolor="#FFFBF0" text="#000000">
<p>
<center>
This Bulletin Board begun on 07-07-97
</center>
</p>
<!--begin-->


</body>
</html>

0
Comment
Question by:dmanb
2 Comments
 
LVL 5

Accepted Solution

by:
icd earned 50 total points
ID: 1829002
A number of problems (and perhaps still some more after this answer).

First of all you get a server error when the script is run on your site. Have you set the script to be world executable? Are the files it uses also world read and write?

I was not very sure about the long relative path for the $bull variable. Is this necessary?

The line:-

for($a = 0; $a <= $sizefile; $sizefile++) {

should be

for($a = 0; $a <= $sizefile; $a++) {

(And it should be on one line, perhaps it was wrapped only on experts-exchange).

Your script needs to output to stdout. The minimum should be:-

print <<__END__;
Content-type: text/html

<HTML><HEAD></HEAD><BODY>Hello world</BODY></HTML>
__END__

Note that there must be a blank line after the 'Content-type' and that there must be no white space before or after the final '__END__' line.

You will get an error if you do not output a valid document and this will apply to your 'die' statements. You need to re-code this so that error conditions are printed as an html document.

Fix these problems and we will see if it gets you any further.
0
 

Author Comment

by:dmanb
ID: 1829003
The help from this posting was minimal.  I thank you for your response, but everytime I perl the cgi file, it makes the output file change to 0 bytes.  I have no idea what's going on.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google  (Get  Users Email) 2 135
copy-item script help 15 78
Using VBScript. How to obtain the recomended paging file size? 8 69
Script to change all permissions to my user 7 44
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question