Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can't write form results to file

    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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mex
    Posts
    122
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    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

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    ok thought it would be a permission thing...they so anoying hehe.
    ok cool
    no prob
    sir p

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind I finally found something at www.perl.com/cpan

    But thanks anyway

    Hogtied


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •