Click to See Complete Forum and Search --> : guestbook trouble


gokou
02-04-2003, 05:33 PM
I am new to cgi-bin and I am trying to get a guestbook to work that is off of the htmlgoodies tutorials. I have a directory called cgi-bin and I have the guestbook script inside that directory called guestbook.cgi. I also have the html form page saved in the httpdocs directory. Now, when I fill out the form and hit send, I get an internal Error. What it's suppose to do is send to my email.

Heres the HTML code.


<HTML>
<HEAD>
<TITLE>Guestbook Script</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="brucelee@uogameresources.com">
<B>Write to me below:</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>


Heres the cgi-bin code


#!/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);
}

pyro
02-04-2003, 05:51 PM
I didn't look through any of you code, but one thing you may want to try first is making sure you a) uploaded in ascii, and b) make sure you chmoded your .cgi code.

gokou
02-04-2003, 06:11 PM
It did mention in the tutorial to make sure you upload in ascii or a text editer with no margins. I don't know what they ment by all that. All I did was cut/pasted it into notepad then uploaded it using my ftp.

pyro
02-04-2003, 06:16 PM
Your FTP program should have an "upload as ascii" option. Try looking in the help.

gokou
02-04-2003, 06:30 PM
I dont see an option to switch to ascii. It's not exactly my ftp, it's avahosts(my hosting providers').

pyro
02-04-2003, 08:19 PM
Well, I can tell you now that it's not going to work until you are able to upload in ascii. I think that you can get a lite (free) version of ws_ftp... Yup... http://www.ipswitch.com/downloads/index.html down by the bottom.

gokou
02-04-2003, 09:43 PM
Arigatou gozaimasu! I'm going through the tutorials now.

gokou
02-04-2003, 10:33 PM
I learned about ftp and I uploaded the guestbook.cgi file in ascii. I'm still getting an internal error when I try to post something. guest book page (http://www.uogameresources.com/guestbook.html) If you don't mind, can you try to post something? Maybe you'll know what's wrong after reading the error.

nkaisare
02-04-2003, 10:40 PM
Make sure that you have set correct permissions.

Next, try running the cgi from the shell (telnet/SSH into ur account). See if it runs.

If not, do dos2unix. I dont know what it does, but I needed to do that when I used notepad.

nkaisare
02-04-2003, 10:41 PM
Another suggestion: use CGI.pm module. It really makes life easy.

pyro
02-04-2003, 10:48 PM
I took a look at your script, but a 500 Server Error can mean just about anything. :( That's why I use PHP. :D Anyway, check to make sure your permissions are set up correctly on guestbook.cgi...It probably needs 755 or 777

jeffmott
02-04-2003, 11:39 PM
use CGI::Carp 'fatalsToBrowser';

Use this to display the Perl error message rather than apache's. Though your code compiled fine for me so my guess would be your path to perl is incorrect.

Running dos2unix and uploading in binary is the same as just uploading as text.
DOS2UNIX.EXE converts MS-DOS text files to Unix format, by stripping any CR or end-of-file (Ctrl-Z) characters from the data.

gokou
02-05-2003, 01:11 AM
Thanks for all the suggestions. Looks like I got a few things to study.

gokou
02-05-2003, 01:38 AM
hmm this sucks. I'm reading a tutorial on how to place a cgi script. It says I need to beable to telnet into it. Well after reading the small telnet tutorial, I try to telnet in and it says can't make a connection. Must mean my isp don't allow it? You can do this without telnet, right?

gokou
02-05-2003, 02:21 AM
I figured it out. I had the permission set wrong. cgi scripts permission has to have it set at 700.

nkaisare
02-05-2003, 10:54 AM
The permissions must be set to 755, not 700.

gokou
02-05-2003, 12:24 PM
I had it at 755 and it didn't work. It says in the email that it has to be 700.

jeffmott
02-05-2003, 12:36 PM
That must be a very odd setup you have then, seeing as 755 should work and 700 should not.

gokou
02-05-2003, 07:56 PM
I'm having some other problems with this form. I'm slow modifying it to do other things'. Right now I have it to where it pops up an alert if there is an invalid name or email, but even after the errors, it still loads the thank you page. The thank you page is set up in the cgi script. I'm not sure if I have to make a javascript in the html form page or modify something in the cgi page. I started learning cgi a few days' ago, so if I have to modify the cgi script, that will be pretty hard.

gokou
02-05-2003, 07:59 PM
I forgot to post the url. guest book (http://www.uogameresources.com/guestbook.html) Feel free to test it and give me info. I dont mind the flood of emails'.

Paco Zarabozo
02-07-2003, 05:59 PM
Have you verified if the path you're using for sendmail is the correct path?

Paco.