Solved

HELP WITH MY CGI PLEASE *(or maybe HTML)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now