The first PERL program that I want to write solo will allow my students to answer questions over the web via a form/post method. Getting the below book example program to work is sort of fundamental to writing my student submittal program (I know programs most likely already exist that allow students to submit answers to a teacher over the internet...but I'd like to learn PERL and how to do it myself).<br>
<br>
The below file called "write.cgi" comes straight from a book on PERL5. The program, when combined with a HTML file called "write.html" should allow a web user to enter in some data in various fields, submit the date to ther web server, write the data to a file called 1.html located in a subfolder called 'numbers' located in the folder called 'cgi-bin', and then allow the web user to review the data submitted. <br>
<br>
File "write.cgi" is located in a folder called "cgi-bin". I've confirmed that the file is functional by using the command 'perl write.cgi' which works great. It actually creates a file called 1.html in the 'numbers' subdirectory.<br>
<br>
I've also confirmed that the file is being 'activated' via the web by renaming the file "write.cgi" to "write1.cgi". When I do this I get the 404 file not found html error when I hit the submit key. When the file is called "write.cgi" I don't get a 404 file not found error.<br>
<br>
The web server is a unix system.<br>
write.cgi permissions are set to 755<br>
write.html permissions are set to 744<br>
numbers folder within cgi-bin is set to 755<br>
<br>
Now for the problem. When I access the html file "write.html" from the web I get the form as expected. When I fill in the form and hit the submit button I get the next html screen that allows me to select the file "1.html" which should allow me to go read the file that was created by the "write.cgi" script called "1.html". When I select "1.html" on the web browser, I get a 404 error: file doesn't exist.<br>
<br>
I've checked via telnet and the file 1.html was never created/written on the server.<br>
<br>
Sooo, the error appears to be that I'm not able to write the data on the form via the post method to a file on the server side.<br>
<br>
Can anyone help me here. <br>
<br>
FYI: I have worked this one for awhile. I've double checked the permissions on the folders, etc.<br>
<br>
Thanks again...and below are the two files discussed above.<br>
<br>
Jerry<br>
<br>
<br>
-----"write.html" is shown below without any changes from the book-----------<br>
<br>
<br>
<html><br>
<head><br>
<title>Write.cgi</title><br>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br>
</head><br>
<br>
<body bgcolor="#FFFFFF"><br>
<form method="POST" action="cgi-bin/write.cgi"><br>
<p>Title:<br><br>
<input type="text" name="Student Name" size"20"><br>
</p><br>
<p>Heading:<br><br>
<input type="text" name="Date" size="20"><br>
</p><br>
<p>Body:<br><br>
<textarea rows="4" name="Answer" cols="20" wrap="virtual"></textarea><br>
</p><br>
<p><br>
<input type="submit" value="Submit" name="submit"><br>
<input type="reset" value="Reset" name="reset"><br>
</p><br>
</form><br>
</body><br>
</html><br>
<br>
<br>
---"write.cgi" is shown below without any changes fromt the book I'm using to learn PERL------<br>
<br>
#!/usr/bin/perl<br>
&get_form_data;<br>
print "Content-type: text/html\n\n";<br>
opendir(DIR, "./numbers"<br>
while($name = readdir(DIR))<br>
{<br>
next if $name !~ /^\d*.html/;<br>
push(@files, $name);<br>
}<br>
close(DIR);<br>
if($#files == 0)<br>
{<br>
$nextfile = "1.html";<br>
}<br>
<br>
else<br>
{<br>
<br>
$lastfile = $files[$#files];<br>
$lastfile =~ s/.html//g;<br>
$nextfile = $lastfile + 1;<br>
$nextfile .= ".html";<br>
}<br>
<br>
open(OUT, ">numbers/$nextfile"<br>
print OUT "<HTML>\n<HEAD>\n ";<br>
print OUT "<TITLE>\n";<br>
print OUT "$FORM{'title'}\n";<br>
print OUT "</TITLE>\n";<br>
print OUT "</HEAD>\n";<br>
print OUT "<BODY BGCOLOR=\"#FFFFFF\">\n";<br>
print OUT "<H1>\n";<br>
print OUT "$FORM{'heading'}\n";<br>
print OUT "</H1>\n";<br>
print OUT "<P>\n";<br>
print OUT "$FORM{'body'}\n";<br>
close(OUT);<br>
push(@files, $nextfile);<br>
print "<HTML>\n<BODY>\n";<br>
foreach $file (@files)<br>
{<br>
print "<A HREF=\"numbers/$file\">$file</A>\n";<br>
print "<BR>\n";<br>
}<br>
print "</BODY>\n</HTML>\n";<br>
exit;<br>
<br>
sub get_form_data<br>
{<br>
# Get the input<br>
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );<br>
# Split the name-value pairs<br>
@pairs = split(/&/, $buffer);<br>
foreach $pair (@pairs)<br>
{<br>
($name, $value) = split(/=/, $pair);<br>
# Un-Webify plus signs and %-encoding<br>
$value =~ tr/+/ /;<br>
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;<br>
$value =~ s/<!--(.¦\n)*-->//g;<br>
<br>
$FORM{ $name } = $value;<br>
}<br>
}<br>
<br>
The below file called "write.cgi" comes straight from a book on PERL5. The program, when combined with a HTML file called "write.html" should allow a web user to enter in some data in various fields, submit the date to ther web server, write the data to a file called 1.html located in a subfolder called 'numbers' located in the folder called 'cgi-bin', and then allow the web user to review the data submitted. <br>
<br>
File "write.cgi" is located in a folder called "cgi-bin". I've confirmed that the file is functional by using the command 'perl write.cgi' which works great. It actually creates a file called 1.html in the 'numbers' subdirectory.<br>
<br>
I've also confirmed that the file is being 'activated' via the web by renaming the file "write.cgi" to "write1.cgi". When I do this I get the 404 file not found html error when I hit the submit key. When the file is called "write.cgi" I don't get a 404 file not found error.<br>
<br>
The web server is a unix system.<br>
write.cgi permissions are set to 755<br>
write.html permissions are set to 744<br>
numbers folder within cgi-bin is set to 755<br>
<br>
Now for the problem. When I access the html file "write.html" from the web I get the form as expected. When I fill in the form and hit the submit button I get the next html screen that allows me to select the file "1.html" which should allow me to go read the file that was created by the "write.cgi" script called "1.html". When I select "1.html" on the web browser, I get a 404 error: file doesn't exist.<br>
<br>
I've checked via telnet and the file 1.html was never created/written on the server.<br>
<br>
Sooo, the error appears to be that I'm not able to write the data on the form via the post method to a file on the server side.<br>
<br>
Can anyone help me here. <br>
<br>
FYI: I have worked this one for awhile. I've double checked the permissions on the folders, etc.<br>
<br>
Thanks again...and below are the two files discussed above.<br>
<br>
Jerry<br>
<br>
<br>
-----"write.html" is shown below without any changes from the book-----------<br>
<br>
<br>
<html><br>
<head><br>
<title>Write.cgi</title><br>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br>
</head><br>
<br>
<body bgcolor="#FFFFFF"><br>
<form method="POST" action="cgi-bin/write.cgi"><br>
<p>Title:<br><br>
<input type="text" name="Student Name" size"20"><br>
</p><br>
<p>Heading:<br><br>
<input type="text" name="Date" size="20"><br>
</p><br>
<p>Body:<br><br>
<textarea rows="4" name="Answer" cols="20" wrap="virtual"></textarea><br>
</p><br>
<p><br>
<input type="submit" value="Submit" name="submit"><br>
<input type="reset" value="Reset" name="reset"><br>
</p><br>
</form><br>
</body><br>
</html><br>
<br>
<br>
---"write.cgi" is shown below without any changes fromt the book I'm using to learn PERL------<br>
<br>
#!/usr/bin/perl<br>
&get_form_data;<br>
print "Content-type: text/html\n\n";<br>
opendir(DIR, "./numbers"<br>
while($name = readdir(DIR))<br>
{<br>
next if $name !~ /^\d*.html/;<br>
push(@files, $name);<br>
}<br>
close(DIR);<br>
if($#files == 0)<br>
{<br>
$nextfile = "1.html";<br>
}<br>
<br>
else<br>
{<br>
<br>
$lastfile = $files[$#files];<br>
$lastfile =~ s/.html//g;<br>
$nextfile = $lastfile + 1;<br>
$nextfile .= ".html";<br>
}<br>
<br>
open(OUT, ">numbers/$nextfile"<br>
print OUT "<HTML>\n<HEAD>\n ";<br>
print OUT "<TITLE>\n";<br>
print OUT "$FORM{'title'}\n";<br>
print OUT "</TITLE>\n";<br>
print OUT "</HEAD>\n";<br>
print OUT "<BODY BGCOLOR=\"#FFFFFF\">\n";<br>
print OUT "<H1>\n";<br>
print OUT "$FORM{'heading'}\n";<br>
print OUT "</H1>\n";<br>
print OUT "<P>\n";<br>
print OUT "$FORM{'body'}\n";<br>
close(OUT);<br>
push(@files, $nextfile);<br>
print "<HTML>\n<BODY>\n";<br>
foreach $file (@files)<br>
{<br>
print "<A HREF=\"numbers/$file\">$file</A>\n";<br>
print "<BR>\n";<br>
}<br>
print "</BODY>\n</HTML>\n";<br>
exit;<br>
<br>
sub get_form_data<br>
{<br>
# Get the input<br>
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );<br>
# Split the name-value pairs<br>
@pairs = split(/&/, $buffer);<br>
foreach $pair (@pairs)<br>
{<br>
($name, $value) = split(/=/, $pair);<br>
# Un-Webify plus signs and %-encoding<br>
$value =~ tr/+/ /;<br>
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;<br>
$value =~ s/<!--(.¦\n)*-->//g;<br>
<br>
$FORM{ $name } = $value;<br>
}<br>
}<br>