[ back to toc ]

What Is Wrong?

Date: 2002/01/01 06:05

Q:
I'm sending you a script of message board and I don't know what is wrong
with it so I'm beggin you to help me!!!

#!/usr/bin/perl

$postpage = "http://www.*NAME-DELETED*.com/MessageBoard.htm";
$postname = "SysCold Message Board";
$postpath = "/home/users/*NAME-DELETED*.com/public_html/MessageBoard.htm";
$cgilocation = "http://www.*NAME-DELETED*.com/cgi-bin/post.cgi";
$mailprog = '/bin/mail';
$youmail = 'webmaster@*NAME-DELETED*.com';
$yourname = "SysCold";
$getdate = "/bin/date";

# Get Date and Time from Server
$date = '$getdate +"%B %d, %Y"'; chop($date);

# Receive info from Posting
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/<([^>]|\n)*>//g;
$INPUT{$name} = $value;
}

# Give error message to left out categories
&no_name unless $INPUT{'name'};
&no_post unless $INPUT{'post'};

# Write info to Post Page
open (FILE,"$postpath") || die "Can't Open $postpath: $!\n";
@lines = <FILE>;
close(FILE);

# Open Link File to Output
open (POST,">$postpath") || die "Can't Open $postpath: $!\n";

foreach $line (@lines) {
if ($line =~ /<!--begin-->/)

print POST ("<!--begin-->\n");
print POST ("<table width=75% border=8 cellspacing=5>\n");
print POST ("<tr>\n");
print POST ("<td height=24 width=12%>From</td>\n");
print POST ("<td height=24 width=88%>$INPUT{'name'}</td>\n");
print POST ("</tr>\n");
print POST ("<tr>\n");
if ($INPUT{'email'}) {
print POST ("<td width=12%>E-mail</td>\n");
print POST ("<td widtd=88%><a
href=\mailto:$INPUT{'email'}\">$INPUT{'email'}</a></td>\n");
} else {
print POST ("<td width=12%>E-mail</td>\n");
print POST ("<td widtd=88%>Author Does Not Have Mail</td>\n");
}
print POST ("</tr>\n");
print POST ("<tr>\n");
print POST ("<td width=12%>Subject</td>\n");
print POST ("<td width=88%>$INPUT{'subject'}</td>\n");
print POST ("</tr>\n");
print POST ("<tr>\n");
print POST ("<td width=12%>Date</td>\n");
print POST ("<td width=88%>$date</td>\n");
print POST ("</tr>\n");
print POST ("<tr>\n");
print POST ("<td width=12%>Message</td>\n");
print POST ("<td width=88%>$INPUT{'post'}</td>\n");
print POST ("</tr>\n");
print POST ("</table>\n");
}

close (POST);

# Send info to you

open (MAIL, "|$mailprog $youmail");

if ($INPUT{'email'} =~ /(.*)@(.*)/) {
print MAIL "From: $INPUT{'name'} <$INPUT{'email'}>\n";
} else {
print MAIL "From: $INPUT{'name'}\n";
}
print MAIL ("Subject: Posting\n\n");
print MAIL ("$INPUT{'name'} Has Posted Message.\n\n");
print MAIL ("You Can Response To This Message Via Email At
$INPUT{'email'}\n\n");
print MAIL ("Here Is The New Message:\n\n");
print MAIL ("$INPUT{'name'}\n");
if ( $INPUT{'email'} ){
print MAIL ("$INPUT{'email'}\n");
}
print MAIL ("$date\n");
print MAIL
("----------------------------------------------------------\n\n");
if ($INPUT{'post'}) {
print MAIL ("$INPUT{'post'}");
}

close (MAIL);

# Send info to visitor
if ($INPUT{'email'}) {
if ($INPUT{'email'} =~ /(.*)@(.*)/) {
open (MAIL, "|-") || exec $mailprog,$INPUT{'email'} || die "Can't open
$mailprog!\n";
print MAIL ("From: $yourname <$youmail>\n");
print MAIL ("Subject: Posting\n\n");
print MAIL ("$INPUT{'name'},\n\n");
print MAIL ("Thank You For Posting Message On My Page! You Can See Your
Message At $postpage\n");
print MAIL ("If You Want To Contact Me From Any Reason Just Send Me
email at $youmail.\n\n");
print MAIL ("Thanks again!\n");
close (MAIL);
}
}

&follow_up;

# Error Messages

sub no_name {

print ("Content-type: text/html\n\n");
print ("<html><head><title>There Is No Name</title></head>\n");
print ("<body bgcolor=#000000 text=#00CC33 link=#FFFF00 vlink=#FF0000><h1
align=center>You Did Not Enter Your Name</h1>\n");
print ("If You Do Not Want Others To See Your Name Just Enter Anonymous As
Name.\n");
print ("Becouse You Did Not Enter Your Name Your Message Was Not
Posted.\n");
print ("Please Enter Your Name Below.<br>\n");
print ("<form method=POST action=\"$cgilocation\">\n");
print ("Your Name:<input type=text name=\"name\" size=30><br>\n");
print ("<input type=hidden name=\"email\" value=\"$INPUT{'email'}\"
size=40><br>\n");
print ("<input type=hidden name=\"post\" value=\"$INPUT{'post'}\">\n");
print ("<input type=submit value=\"Try Again\"><hr>\n");
print ("</body></html>\n");

exit;

}

sub no_post {

print ("Content-type: text/html\n\n");
print ("<html><head><title>No Text In Your Message</title></head>\n");
print ("<body bgcolor=#000000 text=#00CC33 link=#FFFF00 vlink=#FF0000><h1
align=center>Your Message Is Blank!Please Write Text Of Your
Message!</h1>\n");
print ("Becouse Your Message Had No Text It Has Not Been Posted\n");
print ("Please Enter Text Of Your Message Below:<br>\n");
print ("<form method=POST action=\"$cgilocation\">\n");
print ("<textarea name=\"post\" COLS=60 ROWS=4></textarea>\n");
print ("<input type=hidden name=\"name\" value=\"$INPUT{'name'}\"
size=30><br>\n");
print ("<input type=hidden name=\"email\" value=\"$INPUT{'email'}\"
size=40><br>\n");
print ("<input type=submit value=\"Post Again\"><hr>\n");
print ("</body></html>\n");

exit;

}

# Print Follow Up HTML
sub follow_up {

print ("Content-Type: text/html\n\n");
print ("<html><head><title>Thank You</title></head>\n");
print ("<body bgcolor=#000000 text=#00CC33 link=#FFFF00 vlink=#FF0000><h1
align=center>Thank You For Posting Message On My Message Board</h1>\n");
print ("Your Message Has Been Successfully Posted On My Message
Board.<hr>\n");
print ("This Is The Text Of Message You Posted:<p>\n");
print ("<b>$INPUT{'name'}</b><br>\n");
if ($INPUT{'email'}) {
print ("<a href=\"mailto:$INPUT{'email'}\">$INPUT{'email'}</a><br>\n");
}
print ("$date<hr>\n");
if ($INPUT{'post'}) {
print ("$INPUT{'post'}<hr>\n");
}
print ("<a href=\"$postpage\">Back to $postname</a>. \n");
print ("If you do not see your message, hit REFRESH<br>\n");

exit;

}
A:
There is a syntax error in the program. TO get this knowledge you should
have some Pelr interpreter at the command line and issue the command

perl -c myprog.pl

that will actually test the code.

In this very case you forgot to close a curly bracket that belongs to the
line

foreach $line (@lines)

Where it is missing from you should know better, what you want to achieve
actually.

Regards,
Peter

[ back to toc ]