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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
writing to files



Oct 24, 2001, 10:58 AM

Post #1 of 3 (1291 views)
writing to files Can't Post

help! i am trying to write the contents of an html form to a file with a cgi script, but for some reason when i execute the script nothing is happening. i have tried perl -cw command and the syntax is fine-- does anyone have any idea why this wouldn't work? here is the script, if that helps:


print "Content-type:text/html\n\n";

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;
$value =~ s/\n/ /g; # replace newlines with spaces
$value =~ s/\r//g; # remove hard returns
$value =~ s/\cM//g; # delete ^M's
$FORM{$name} = $value;

open (LOGFILE,">>/gagehouse/cgi-bin/data_files/jha.log") or dienice("Cannot open jha.log for writing: $!");

# this locks the file so no other CGI can write to it at the same time

# reset the file pointer to the end of the file, in case
# someone wrote to it while we waited for the lock


print LOGFILE ("$newline\n");
close LOGFILE;

#this next line won't let the 'stationnumber' field be left blank
if ($FORM{'stationnumber'} eq "") {
dienice("Please enter a station number into the JHA form.");
} else
{print "<BODY BGCOLOR=\"#cccc99\" text=\"#003300\"><BR><BR><H1 align=center>Thank you. The Job Hazard Analysis for this site has been updated.</H1>";

#dienice subroutine, for handling errors
sub dienice {
my($errmsg) = @_;
print "<h2>Error</H2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";


Oct 24, 2001, 1:10 PM

Post #2 of 3 (1288 views)
Re: writing to files [In reply to] Can't Post

I only see @value once.

on this line ---

If @value has no values to join then $newline eq ""

Do you want to add your form data to @value like this?

@value = ($FORM{'stationnumber'} ", "$FORM{'moreformdata'}", "$FORM{'evenmoreformdata'}");


Oct 24, 2001, 3:16 PM

Post #3 of 3 (1282 views)
Re: writing to files [In reply to] Can't Post

thank you so much! an obvious mistake, but i think i had just been thinking about it way too much. thanks for pointing it out for me...


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

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