View Full Version : can't write form results to file
hogtied
06-20-2002, 09:26 AM
Hey people, I'm having trouble here with Perl, CGI. It's an email address only.
The form spits out to the url ?txtEmail=ggg@ggg.com
Once i click on the submit button a error page comes back saying that i have a malformed header..
Heres my CGI code..
#!/usr/local/bin/perl
read(STDIN, $buffer, $ENV{'COTENT_LENGTH'});
@pairs = split (/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split (/=/, $pair);
$email{$name} = $value;
}
$emailFile = "newsletter.txt";
open (FILE, ">>$emailFile");
print FILE "$email{'txtEmail'}";
close (FILE);
i know something is wrong.. im kinda new to this and learning.. Have bought a book called "Perl, CGI, and JavaScript" it's an OK book but it's not helping.. I got this code from the book and it resembles a lot of others codes out there on the web... SO....
Thanks,
Hogtied :D
chrisvmarle
06-20-2002, 04:25 PM
You get the error "Malformed header" 'cuz there's no header at all. On the web you must send a header, as far as I know.
To send a simple HTML header add
print "Content-type: text/html\n\n";
anywhere to your script and see if that helps.
Mzzl, Chris
hogtied
06-22-2002, 05:13 AM
well now i don't get the malformed header error but it doesn't write to the file either... do you have any idea why this might be.. The CGI folder does have read/write permissions. And I searched every website that showed you how to write to files. And my code is exactly like theirs with the changed variables of course...
Calilo
06-22-2002, 07:01 AM
the script looks perfecly fine, perhaps you should try printing some text to the files like this,
print FILE "Try, TRy";
just to see if that part is working fine,
calilo
hogtied
06-22-2002, 11:53 PM
ive entered the statment:
print FILE "Hello";
and it didn't write anything to the file called newsletter.txt which is in the same CGI folder... I called my web hosting company and they suggested that the code might be the probelm because they don't see any errors at their end.
I have no idea, and as far as i know this should work.... i even tried changing the 'CONTENT_LENGTH' to 'QUERY_STRING' and that didn't work....
Does anyone have any ideas...???
Thanks guys,
Hogtied :confused:
sir pannels
06-23-2002, 02:28 PM
yeh that is deffo a permission problem..i just ran your script on my computer...and its fine....so make sure newsletter.txt is chmod to 777 ..you shouldnt need to chmod its dir but now and again i found i had to on diferent hosts.
sir p
hogtied
06-24-2002, 01:45 AM
Thanks guys i happened to be a permission error.. Had to create a CGI Zone.. Well any way guys thanks for the help....
Thanks
Hogtied :thumbsup:
sir pannels
06-24-2002, 01:58 AM
ok thought it would be a permission thing...they so anoying hehe.
ok cool
no prob:)
sir p
hogtied
06-24-2002, 07:35 AM
yeah thanks again sirP. Have another question though, I've have looked everywhere for this code and can't find it. Want, in perl, to set a variable to today's date. I thought it would be something like this
$date = new Date();
but it's not.. See I thought it would be the same as most languages. And I've looked everywhere to see how this would be done but no one explains it. Is there a way to get today's date or do you have to create a variable of today's date with javascript and send it to the CGI??
Thanks,
Hogtied :)
hogtied
06-24-2002, 07:48 AM
Nevermind I finally found something at www.perl.com/cpan (http://www.perl.com/cpan)
But thanks anyway
Hogtied:p
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.