Click to See Complete Forum and Search --> : 404 error


menotyou
01-31-2006, 07:37 PM
i created the script in notepad saved it with .txt extension (couldnt figure out how to save it as .cgi) uploaded it to the server thru dreamweaver and when i try to run it i get a 404 error because i cant figure out how to save it with the right extension. hope someone can help and i hope my explaination made sense. thanks.

menotyou

Scriptage
02-01-2006, 02:24 AM
A 404 error means the file can't be found so make sure that you have the correct address and make sure you are uploading into the right place. The file won't run anyway because of the .txt extension. When you save a file type the filename (ie myscript.cgi) in the first box and then underneath change the selection box to "All files". Sorry if I don't make an awful lot of sense but it's early.

Regards

Carl

menotyou
02-01-2006, 02:28 PM
thank you. i did that and it worked. i had also forgot to change the permission. now ive run into another prob: i cant get the script on <a href="http://fountainsoflivingwater.com/requestform.html"> this </a> page to run.

here is the relevant code:

<form method="post" action="http://fountainsoflivingwater.com/cgi-bin/requestform.cgi">

<INPUT NAME="name" SIZE=50 TYPE="text"> <strong>Your Name</strong><BR>
<INPUT NAME="email" SIZE=50 TYPE="text"> <strong>Your E-Mail Address </strong> <BR>
<br />
<INPUT TYPE="hidden" NAME="submitaddress" VALUE="bballkris_@hotmail.com">
<br />
<strong> Please provide details about your request below and a contact number </strong>
<br />

<SELECT NAME="request" SIZE="1">
<option selected value="admin">Admin Request
<option value="address">Address Change
<option value="counseling">Counseling Request
<option value="prayer">Prayer Request
<option value="apostle">Booking Request
</select>

<p>&nbsp;


<textarea name="comments" ROWS=6 COLS=40>
</TEXTAREA>
<br />
<CENTER>
<INPUT TYPE=submit VALUE="SEND">
<INPUT TYPE=reset VALUE="CLEAR">
</CENTER>

</form>


and here is the code for the script:

#!/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{comments}\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=#428FDD TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";


if($form{request} eq "admin")
{print"<p>Your request will be put into consideration.";}

elsif($form{request} eq "address")
{print"<p>Your address will be updated ASAP.";}

elsif($form{request} eq "counseling")
{print"<p> Someone will be in contact with you to set up an appointment.";}

elsif($form{request} eq "prayer")
{print"<p>We will be praying for your situation.";}

else($form{request} eq "apostle")
{print"<p>Someone will be in contact for further information.";}


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


thank you in advance.

menotyou

cyber1
02-02-2006, 04:54 AM
You have an else conditional thats incorrect.

else does not take a condition. Else is the condition.

else($form{request} eq "apostle"){

should be:
else{

or if you want to add another elsif condition:
elsif($form{request} eq "apostle"){

Then have else be a default
else{
print qq~Sorry can't help you~;
}

-Bill

menotyou
02-02-2006, 08:48 PM
thank you for your assistance. i changed the last condition and it worked. also realized that FORM is case sensitive and that was another reason why it wasnt working. once again thanks.

menotyou

CyCo
02-05-2006, 01:40 PM
Although you have essentially eliminated the syntax errors in your script, more modern programming methods are readily available (and recommended) using CGI.pm. Also, one should utilize some sort of validation for the parameters being returned by the user. Remember, never trust the browser or the user for safe data.