Solved

HELP WITH MY CGI PLEASE *(or maybe HTML)

Posted on 1997-07-09
2
205 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

832 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