Click to See Complete Forum and Search --> : cgi guestbook not working


ripedesign
07-19-2003, 09:40 PM
This is my first attempt at using PERL and I am failing badly.

I am going through the tutorials on the site: http://www.htmlgoodies.com/http://www.htmlgoodies.com/

They have a section called PERL Primers and in there I found a small little follow-the-instructions on making a guestbook which I have been trying to solve for two days. It is the Step 3 sectionStep 3 Section (http://www.htmlgoodies.com/primers/perl/perl03.html) and it is a matter of copy and paste the stuff while following the directions they give.

the file guestbook.html (http://www.theripedesign.com/guestbook.html) is connecting to the file guestbook.cgi as it says in the tutorial. I have done all of that, but I am still getting the error message as follows.

//////////////////////////////////////////////////


Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@theripedesign.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
------------------------------------------------------------------------
Apache/1.3.27 Server at www.theripedesign.com Port 80

//////////////////////////////////////////////////


The tech support for my server said that in an email to me:



//////////////////////////////////////////////////

Your script is broken:

Unrecognized character \xA0 at ./guestbook.cgi line 9.

There is a LARGE number of \xA0 charictors acting as spaces. When you upload the
file, try uploading as ASCI or TEXT mode.

Second problem: there was a newline at the top of the file before the
#!/usr/bin/perl

That needs to be at the top

//////////////////////////////////////////////////



Since this is my first attempt at programming using PERL I am not sure what he is talking about when he says \xA0. But assuming that he meant there was some odd characters that are replacing the spaces with the \xA0 I went ahead and used the edit feature on my server and changed the file again as how I read his email. I went back to the form and an error message (the one I started with.) I don't know what to do. I have emailed tech support about this again, but I thought if anything has some helpful hints I might try in the mean time, they would be greatly appreciated.

Thank you for reading such a L-O-N-G email.

Jeff Mott
07-20-2003, 07:27 PM
I am going through the tutorials on the site: http://www.htmlgoodies.com/This is your first mistake. These primers are not very good at all. See http://learn.perl.org/. You should probably start with Learning Perl (3rd ed), followed by CGI Programming with Perl (2nd ed). After that you should be able to use the free reference documentation at http://www.perldoc.com/.There is a LARGE number of \xA0 charictors acting as spacesThese can't be acting as spaces, however. You need to use actual spaces.Since this is my first attempt at programming using PERL I am not sure what he is talking about when he says \xA0\xa0 is a method of referring to a character without literally typing it. For example, the decimal number for a capital 'A' is 65. The hexadecimal version of this number is 41. So, print "\x41"; will print the character 'A'.

So we can get a better idea of just what the problem is, can you post your script? As an attachment would be preferable.

ripedesign
07-22-2003, 01:27 PM
Unfortunately I can not attach the file, I get an error message saying that the cgi file is not a valid extension.

I will add the text here so that you can see it.


///////////////////////////////////////////////////
#!/usr/bin/perl

# That is the path to PERL just above It MUST be first in the script
# 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 sends the email

___ open (MESSAGE,"| /usr/lib/sendmail -t");

___ print MESSAGE "To: $FORM{submitaddress}\n";
___ print MESSAGE "From: $FORM{name}\n";
___ print MESSAGE "Reply-To: $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";
___ close (MESSAGE);

___ &thank_you;
}

#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";
___ print "<P>\n";
___ print "</BODY>\n";
___ print "</HTML>\n";
___ exit(0);
}

///////////////////////////////////////////////////


So, in the mean time, I have heard back from the other tech support people and they say:

///////////////////////////////////////////////////
///////////////////////////////////////////////////
I'm not sure what BBEditor is, but I'm better that is causing the issue._ From
your .TXT file lines like this stick out:

print &quot;</HTML>\n&quot;;

It looks like your BBEdit is changing Perl code to HTML code, meaning all the "
is now &quote; as well.

Try using a normal TXT file editor like Notepad, or something like that.

Question: Can you no just download the .cgi file and upload to your website?
Then maybe use the (if there are any) editing features of your FTP software to
change the settings? Also, where did you get this guest book?
///////////////////////////////////////////////////
///////////////////////////////////////////////////



I used BBEditor (a mac-version html editor) to copy and paste the text into the guestbook.cgi file. they seem to think that it has something to do with the program, it might, so I took their suggestion and used something similar to Notepad and have had the same results.

Here is what my error log is saying:
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
[2003-07-19 21:55:20]: error: file has no execute permission:
[Tue Jul 22 09:46:36 2003] [error] File does not exist:
[Tue Jul 22 09:46:36 2003] [error] Premature end of script headers:
[Tue Jul 22 09:42:39 2003] [error] File does not exist:
[Tue Jul 22 09:42:39 2003] [error] Premature end of script headers:
[Tue Jul 22 09:40:45 2003] [error] File does not exist:
[Tue Jul 22 09:40:45 2003] [error] Premature end of script headers:
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////

The error log is from today, I have tried it a couple of time so I think that is why I am getting duplicates.

As for the suggestion that tech support made: I have used a TXT file editor called simple text and still nothing. And I am not sure if I understand what he is asking in the first part of his response, should it read with the quotes or should it read with the &quot instead.

I am going to get started on looking at those pages that you suggested. Thanks!

Jeff Mott
07-23-2003, 08:01 AM
What you tech support is saying is that lines such as print "</HTML>\n"; are becoming print &amp;quot;&amp;lt;/HTML&amp;gt;\n&amp;quot;;. This would be the result of using an HTML editor for Perl code. I can't, however, tell you the problem after usning notepad because I can't see the actual script. You will have to try to upload it again. This forum does not accept .cgi for upload so you'll need to change it to .txt.

ripedesign
07-24-2003, 01:02 PM
I see what you mean. I have tried to change it several times, but I can not seem to get it to stick.

I am attaching the txt version of the CGI file. I made it into a CGI file using SimpleText which is a Apple text editor similar to NotePad or Write on windows.

This is what the code looks like in SimpleText--yes I see the [ &amp;quot; ] section that was mentioned earlier. Also, you can check out the actual code from the URL I got it from in the above posting.

Thank you!


________________________________

#!/usr/bin/perl

# That is the path to PERL just above It MUST be first in the script
# 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 sends the email

___ open (MESSAGE,"| /usr/lib/sendmail -t");

___ print MESSAGE "To: $FORM{submitaddress}\n";
___ print MESSAGE "From: $FORM{name}\n";
___ print MESSAGE "Reply-To: $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";
___ close (MESSAGE);

___ &thank_you;
}

#0The following creates the Thank You page display
sub thank_you {

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

Jeff Mott
07-24-2003, 01:30 PM
Your code contains may Ê characters where there shouldn't be. These need to go. And, as your tech support says, in your thank_you subroutine you have HTML entities where there should be quotes. You need to change these entities back to the characters they're supposed to be.

Thuy
07-30-2003, 08:22 PM
Hi Jeff and Ripedesign,

I am using text editor to edit the guestbook.pl and install it to my second server. Knowing that the guestbook.pl works fine from my first server. I got the error message "Application Error" from the installed module. I guessed the text editor that I used causing this type of error.

I am also new to Perl program and I wonder if we have any good Perl editor to use? Your advices are greatly appreciated.

The attached file is my guestbook.pl
Thank you,
Thuy

ken_walker_jr
08-03-2003, 03:42 PM
The best editor on the planet.

http://www.multiedit.com/

syntax highlighting, spectacular search n replace, macros, you name it.