CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Why isnt this working...

 



SaiyanM
User

Feb 4, 2001, 3:11 PM

Post #1 of 8 (794 views)
Why isnt this working... Can't Post

I made this cgi guestbook, I want to know why it doesnt work...

#!/usr/local/bin/perl

$qstring = $ENV{'QUERY_STRING'};
$site_name = Saiyan Menacy

####### This is the absolute pathname of the email log.
$guestbook="/data1/virtualave.net/saiyanh/public_html/emaillog.html";

####### The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {

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;

$FORM{$name} = $value;
}


######## The following code posts the log entry

open (GUESTBOOK,"<< $guestbook");
$currenttime=localtime;

######## We now add the entry to $GUESTBOOK
print GUESTBOOK "$currenttime from $ENV{'REMOTE_HOST'}<BR>\n";
print GUESTBOOK "<FONT SIZE=+1>$FORM{name}<\FONT>";<BR>
print GUESTBOOK " [<A HREF=\"mailto:$FORM{email}\"><I>$FORM{email}</I></A>]<BR>";
print GUESTBOOK "<P><FONT SIZE=+1>The user writes:<\FONT><BR>";
print GUESTBOOK "$FORM{feedback}<HR><P>\n";
close (GUESTBOOK);

###### The following sends the email

open (MESSAGE,"| /var/qmail/bin/qmail-inject");

print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{name}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Cc: $FORM{$email}\n";

print MESSAGE "Subject: Feedback from $FORM{name} at $ENV{'REMOTE_HOST'}\n\n";
print MESSAGE "The user wrote:\n\n";
print MESSAGE "$FORM{feedback}\n";


######The following creates the Thank You page display

sub thank_you {

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Thank You!</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFCC TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";
print "<H3>Your feedback is greatly appreciated.<BR>\n";

if ($FORM{newsletter} eq "yes")
{print " "; }
elsif ($FORM{newsletter} eq "no")
{print " "; }
else
{print ""}

print "<P>\n";
print "</BODY>\n";
print "</HTML>\n";
exit(0);
}

###########This makes the form
if ($qstring eq "sign") {
print "Content-type: text/html\n\n;"
print "<<FORM;

<HTML>
<HEAD>
<TITLE>Sign $site_name 's Guestbook</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<FORM METHOD="post" ACTION="/cgi-bin/guestbook.cgi">

<INPUT NAME="name" SIZE=50 TYPE="text"> <B>Your Name</B><BR>
<INPUT NAME="email" SIZE=50 TYPE="text"> <B>Your E-Mail Address</B><BR>
<INPUT TYPE="hidden" NAME="submitaddress" VALUE="SaiyanM@hotmail.com">
<B>Comments</B><P>
<TEXTAREA NAME="feedback" ROWS=10 COLS=50></TEXTAREA><P>

<CENTER>
<INPUT TYPE=submit VALUE="SEND">
<INPUT TYPE=reset VALUE="CLEAR">
</CENTER>

</FORM>

</BODY>
</HTML>

FORM
exit;
}





muinatit
Deleted

Feb 4, 2001, 5:56 PM

Post #2 of 8 (789 views)
Re: Why isnt this working... [In reply to] Can't Post

Change this:

$site_name = Saiyan Menacy

To this:


Code
$site_name = "Saiyan Menacy";

muinatit
muinatit@hotpop.com


SaiyanM
User

Feb 5, 2001, 2:27 PM

Post #3 of 8 (783 views)
Re: Why isnt this working... [In reply to] Can't Post

Nope, that didnt help. SOMEBODY PLEASE LOOK OVER THIS, I NEED HELP!



japhy
Enthusiast

Feb 5, 2001, 2:33 PM

Post #4 of 8 (781 views)
Re: Why isnt this working... [In reply to] Can't Post

You obviously haven't tried running this from the command-line. I find several errors upon visual inspection:

1. you're not using CGI.pm for getting at the CGI query -- this is bound to make you unhappy soon

2. your string "Saiyan Menacy" isn't quoted -- it needs to be

3. you open the guestbook with "<<", instead of ">>"

4. your here-doc, print "<<FORM;, has a " that is not supposed to be there (it should just be print <<FORM;)

And there's no need to shout, and there's no need to demand service from the volunteers spending time from their day here on the forum.


Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


SaiyanM
User

Feb 5, 2001, 2:40 PM

Post #5 of 8 (779 views)
Re: Why isnt this working... [In reply to] Can't Post

the thing you mentioned about the cgi.pm, where can you find that? and please tell me how to use it, thanks



muinatit
Deleted

Feb 5, 2001, 4:22 PM

Post #6 of 8 (774 views)
Re: Why isnt this working... [In reply to] Can't Post

Actually, I dont think he needs CGI.pm, he has his own parser.

muinatit
muinatit@hotpop.com


japhy
Enthusiast

Feb 5, 2001, 5:20 PM

Post #7 of 8 (773 views)
Re: Why isnt this working... [In reply to] Can't Post

Right, and it's totally fool-proof. (That's sarcasm.)

1. it will break on non-POST queries

2. it will break on queries with checkboxes (or other fields) of the same name

3. it will break on file uploads

4. it is cargo-cult, and is used without having the slightest idea WHY

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


muinatit
Deleted

Feb 5, 2001, 6:14 PM

Post #8 of 8 (771 views)
Re: Why isnt this working... [In reply to] Can't Post

I know. But he seems confused as is, so....... err nevermind. I just got a memory lapse. Don't you hate those?

muinatit
muinatit@hotpop.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives