Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How can i write the values of a form through a cgi script in a txt file.

Reply
Thread Tools

How can i write the values of a form through a cgi script in a txt file.

 
 
JR
Guest
Posts: n/a
 
      10-15-2003
How can i write the values of a form through a cgi script in a txt file.

My html pages is for example:

<FORM METHOD=POST ACTION="script.cgi">
<input type="text" name="nummer" size="20"></p>
<p><input type="text" name="paswoord" size="20"></p>
<p><input type="submit" value="Submit" name="Send">
</form>

Can anybody help me with this simple script
I am a newbie and i would love to learn perl/cgi.


Thanks
 
Reply With Quote
 
 
 
 
Anand
Guest
Posts: n/a
 
      10-15-2003
In your cgi script names 'script.cgi' you can get values of parameter
passed. You have to write values to file in this script.
Let me know if you need some more input.

--Anand

JR wrote:
> How can i write the values of a form through a cgi script in a txt file.
>
> My html pages is for example:
>
> <FORM METHOD=POST ACTION="script.cgi">
> <input type="text" name="nummer" size="20"></p>
> <p><input type="text" name="paswoord" size="20"></p>
> <p><input type="submit" value="Submit" name="Send">
> </form>
>
> Can anybody help me with this simple script
> I am a newbie and i would love to learn perl/cgi.
>
>
> Thanks


 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      10-16-2003
On Wed, 15 Oct 2003 10:33:23 -0700, JR wrote:
> How can i write the values of a form through a cgi script in a txt file.


What have you tried so far? What doesn't work?


--
Tore Aursand <>
 
Reply With Quote
 
JR
Guest
Posts: n/a
 
      10-17-2003
Tore Aursand <> wrote in message news:<>.. .
> On Thu, 16 Oct 2003 12:57:41 -0700, JR wrote:
> >>> How can i write the values of a form through a cgi script in a txt file.

>
> >> What have you tried so far? What doesn't work?

>
> > #!/usr/bin/perl

>
> Should be:
>
> #!/usr/bin/perl
> #
> use strict;
> use warnings;
>
> > 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;
> > $FORM{$name} = $value;
> > }

>
> Should be:
>
> use CGI;
>
> my $cgi = CGI->new();
> print $cgi->header(-type => 'text/html');
>
> > open (EEP,"passwords.txt");foreach $key (keys(%FORM)) {
> > print EEP "$key = $FORM{$key}<br>";
> > }

>
> Should be:
>
> my $params = $cgi->Vars();
> open( EEP, '>passwords.txt' ) || die "$!";
> foreach my $key ( keys %$params ) {
> print EEP $key . ' = ' . $params{$key} . '<br';
> }
> close( EEP );
>
> But why do you want to write some HTML to STDOUT, while the form data gets
> written to a text file?
>
> Summary:
>
> perldoc CGI
> perldoc -f open


I tried your code but i get the follow error

Status: 302 Found Location:
/bin/error?error=Your%20script%20produced%20this%20erro r%3A%20%3Cbr%3EUndefined%20subroutine%20CGI%3A%3AV ars%20at%20CGI.pm%20line%20349.
URI: /bin/error?error=Your%20script%20produced%20this%20erro r%3A%20%3Cbr%3EUndefined%20subroutine%20CGI%3A%3AV ars%20at%20CGI.pm%20line%20349.
Content-type: text/html
 
Reply With Quote
 
Tore Aursand
Guest
Posts: n/a
 
      10-19-2003
On Fri, 17 Oct 2003 12:01:16 -0700, JR wrote:
> I tried your code but i get the follow error


Please post the complete code.


--
Tore Aursand <>
 
Reply With Quote
 
JR
Guest
Posts: n/a
 
      10-19-2003
Tore Aursand <> wrote in message news:<>.. .
> On Fri, 17 Oct 2003 12:01:16 -0700, JR wrote:
> > I tried your code but i get the follow error

>
> Please post the complete code.


#!/usr/bin/perl
#
use strict;
use warnings;

use CGI;
my $cgi = CGI->new();
print $cgi->header(-type => 'text/html');

my $params = $cgi->Vars();
open( EEP, '>passwords.txt' ) || die "$!";
foreach my $key ( keys %$params ) {
print EEP $key . ' = ' . $params{$key} . '<br';
}
close( EEP );

this is my complete code

Thanks

Jo
 
Reply With Quote
 
Eric Bohlman
Guest
Posts: n/a
 
      10-19-2003
(JR) wrote in
news: om:

> foreach my $key ( keys %$params ) {


Here you treat $params as the hash reference it is...

> print EEP $key . ' = ' . $params{$key} . '<br';


But here you're not dereferencing it, instead you're trying to look up the
key in the non-existent hash %params. You want $params->{$key}, or
$$params{$key} if you prefer (though I find the arrow-style easier to
read).
 
Reply With Quote
 
Tore Aursand
Guest
Posts: n/a
 
      10-20-2003
On Sun, 19 Oct 2003 11:15:09 -0700, JR wrote:
>> Please post the complete code.


> [...]
> this is my complete code


That's impossible. You told in the previous message that you got this
error message:

Undefined subroutine CGI::Vars at CGI.pm line 349

When I run your code - as posted by you - I don't receive this error
message. I get, however, an other error:

Global symbol "%params" requires explicit package name [...]

And that's because you're not dereferencing your hash when printing it out;

print EEP $key . ' = ' . $params{$key} . '<br';
^^^^^^^^^^^^^
You should use '$params->{$key}' instead.


--
Tore Aursand <>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 9.14 How do I make sure users can't enter values into a form that cause my CGI script to do bad things? PerlFAQ Server Perl Misc 0 03-30-2011 10:00 AM
FAQ 9.14 How do I make sure users can't enter values into a form that cause my CGI script to do bad things? PerlFAQ Server Perl Misc 4 01-03-2011 01:16 AM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
Can't write to a text file through CGI-Perl Kishore Perl Misc 1 08-30-2004 04:11 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57