Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] writing form data

Expand Messages
  • tnas
    Did you check if the parameters from the POST are with a defined value ? ... -- Thiago Nascimento #!/usr/bin/perl $_= tMM naaCt
    Message 1 of 9 , Sep 11, 2006
    • 0 Attachment
      Did you check if the parameters from the POST are with a defined value ?

      ballast_boy escreveu:
      >
      > I still can't get it to write to file. Here is all the code;
      >
      > #!/user/bin/perl -w
      > use CGI qw(param);
      > $query = new CGI;
      > print $query->header;
      >
      > open (USERINFO, ">/home/tomcat/passchk/userinfo.txt") or
      > die "Cannot open /home/tomcat/passchk/userinfo.txt : $!";
      >
      > print USERINFO param("name"), param("pass");
      > close (USERINFO);
      >
      > That's it. Short and should be simple. I know I'm missing
      > something that should be easy but I just can't spot it.
      >
      > Thanks for all the advice,
      >
      > William
      >
      > --- In perl-beginner@yahoogroups.com
      > <mailto:perl-beginner%40yahoogroups.com>, merlyn@... wrote:
      > >
      > > >>>>> "ballast" == ballast boy <ballast_boy@...> writes:
      > >
      > > ballast> Help! I'm new to perl but I have gotten some things
      > down. I know how
      > > ballast> to open and read files. I've got a form on the web that
      > I can get
      > > ballast> information from and either print it at my Unix screen or
      > back to the
      > > ballast> web. Here's my problem. How do you get info from a form
      > (I use Post
      > > ballast> as method) and write it to a text file on my server? Yes
      > the file is
      > > ballast> writable. Here is what I have;
      > > ballast> (usual perl stuff here)
      > > ballast> print $query->header;
      > >
      > > ballast> $query->param('name');
      > > ballast> $query->param('pass');
      > >
      > > ballast> #I need to write it to here****
      > >
      > > ballast> open (UserInfo, '>/home/tomcat/passchk/userinfo.txt');
      > >
      > > Always use the "open ... or die" idiom.
      > >
      > > ballast> Looks simple but I have tried eveything and can't get it
      > to work. I'm
      > > ballast> afraid either my computer, Larry Wall or myself is going
      > to get hurt
      > > ballast> if I don't figure this out soon ;)
      > >
      > > If you just want to print those two params into the file:
      > >
      > > use CGI qw(param); # I hate typing $query->param everywhere
      > > open OUTFILE, ">/my/output/file" or die "Cannot
      > create /my/output/file: $!";
      > > print OUTFILE param("name"), param("pass");
      > > close OUTFILE;
      > > ... rest of CGI output has to happen here ...
      > >
      > > However, you'll probably want some sort of delimiter around the two
      > > values. Keep in mind that every possible character could be coming
      > > in from these params, so either regex-clean them first, or use a
      > storage
      > > system that can delimit any possible character.
      > >
      > > --
      > > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
      > 777 0095
      > > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/
      > <http://www.stonehenge.com/merlyn/>>
      > > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      > > See PerlTraining.Stonehenge.com for onsite and open-enrollment
      > Perl training!
      > >
      >
      >

      --
      Thiago Nascimento
      #!/usr/bin/perl
      $_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while s/(..)(.)//;print substr$_,1,1;
    • Charles K. Clarkson
      ... Test a smaller case. CGI.pm allows us to stuff field values to detect problems. If this succeeds, then the form is in error. If this fails you should see
      Message 2 of 9 , Sep 11, 2006
      • 0 Attachment
        ballast_boy wrote:

        : That's it. Short and should be simple. I know I'm missing
        : something that should be easy but I just can't spot it.

        Test a smaller case. CGI.pm allows us to stuff field
        values to detect problems. If this succeeds, then the form
        is in error. If this fails you should see why. Call this
        script directly, not through the form. You may need to change
        the value in href on line 28 to navigate to the file.


        #!/user/bin/perl

        use warnings;
        use strict;

        use CGI::Carp 'fatalsToBrowser'; # only for testing

        use CGI;
        my $query = CGI->new();

        # add form input
        $query->param( name => 'name' );
        $query->param( pass => 'pass' );

        open USERINFO, '>/home/tomcat/passchk/userinfo.txt' or
        die "Cannot open /home/tomcat/passchk/userinfo.txt: $!";

        print USERINFO $query->param('name'), $query->param('pass');

        close USERINFO;

        print
        $query->header(),
        $query->start_html( -title => 'User Name / Password Test' ),
        $query->p(
        'The test seems to be successful.',
        $query->a(
        { -href => '/home/tomcat/passchk/userinfo.txt' },
        'View file',
        ),
        '.',
        ),
        $query->end_html();

        __END__


        HTH,

        Charles K. Clarkson
        --
        Mobile Homes Specialist
        Free Market Advocate
        Web Programmer

        254 968-8328

        Don't tread on my bandwidth. Trim your posts.
      • ballast_boy
        Here is the form: UserName:
        Message 3 of 9 , Sep 11, 2006
        • 0 Attachment
          Here is the form:

          <body>
          <FORM METHOD="POST" ACTION="/cgi-bin/userchk.cgi">
          <div align="center">
          <p>UserName:
          <INPUT TYPE="text" NAME="name">
          <br />
          <BR>
          Password:
          <INPUT TYPE="password" NAME="pass">
          <BR>
          </p>
          <p align="center">
          <INPUT TYPE="SUBMIT" VALUE="Submit">
          </p>
          </div>
          </FORM>

          </body>
          </html>

          I'm lost.

          William

          --- In perl-beginner@yahoogroups.com, tnas <nascimentothiago@...>
          wrote:
          >
          > Did you check if the parameters from the POST are with a defined
          value ?
          >
          > ballast_boy escreveu:
          > >
          > > I still can't get it to write to file. Here is all the code;
          > >
          > > #!/user/bin/perl -w
          > > use CGI qw(param);
          > > $query = new CGI;
          > > print $query->header;
          > >
          > > open (USERINFO, ">/home/tomcat/passchk/userinfo.txt") or
          > > die "Cannot open /home/tomcat/passchk/userinfo.txt : $!";
          > >
          > > print USERINFO param("name"), param("pass");
          > > close (USERINFO);
          > >
          > > That's it. Short and should be simple. I know I'm missing
          > > something that should be easy but I just can't spot it.
          > >
          > > Thanks for all the advice,
          > >
          > > William
          > >
          > > --- In perl-beginner@yahoogroups.com
          > > <mailto:perl-beginner%40yahoogroups.com>, merlyn@ wrote:
          > > >
          > > > >>>>> "ballast" == ballast boy <ballast_boy@> writes:
          > > >
          > > > ballast> Help! I'm new to perl but I have gotten some things
          > > down. I know how
          > > > ballast> to open and read files. I've got a form on the web
          that
          > > I can get
          > > > ballast> information from and either print it at my Unix
          screen or
          > > back to the
          > > > ballast> web. Here's my problem. How do you get info from a
          form
          > > (I use Post
          > > > ballast> as method) and write it to a text file on my server?
          Yes
          > > the file is
          > > > ballast> writable. Here is what I have;
          > > > ballast> (usual perl stuff here)
          > > > ballast> print $query->header;
          > > >
          > > > ballast> $query->param('name');
          > > > ballast> $query->param('pass');
          > > >
          > > > ballast> #I need to write it to here****
          > > >
          > > > ballast> open (UserInfo, '>/home/tomcat/passchk/userinfo.txt');
          > > >
          > > > Always use the "open ... or die" idiom.
          > > >
          > > > ballast> Looks simple but I have tried eveything and can't get
          it
          > > to work. I'm
          > > > ballast> afraid either my computer, Larry Wall or myself is
          going
          > > to get hurt
          > > > ballast> if I don't figure this out soon ;)
          > > >
          > > > If you just want to print those two params into the file:
          > > >
          > > > use CGI qw(param); # I hate typing $query->param everywhere
          > > > open OUTFILE, ">/my/output/file" or die "Cannot
          > > create /my/output/file: $!";
          > > > print OUTFILE param("name"), param("pass");
          > > > close OUTFILE;
          > > > ... rest of CGI output has to happen here ...
          > > >
          > > > However, you'll probably want some sort of delimiter around
          the two
          > > > values. Keep in mind that every possible character could be
          coming
          > > > in from these params, so either regex-clean them first, or use
          a
          > > storage
          > > > system that can delimit any possible character.
          > > >
          > > > --
          > > > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1
          503
          > > 777 0095
          > > > <merlyn@> <URL:http://www.stonehenge.com/merlyn/
          > > <http://www.stonehenge.com/merlyn/>>
          > > > Perl/Unix/security consulting, Technical writing, Comedy, etc.
          etc.
          > > > See PerlTraining.Stonehenge.com for onsite and open-enrollment
          > > Perl training!
          > > >
          > >
          > >
          >
          > --
          > Thiago Nascimento
          > #!/usr/bin/perl
          > $_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while s/(..)
          (.)//;print substr$_,1,1;
          >
        • tnas
          For you debug your code, try this: use Data::Dumper; my %fromweb = map { $_ = $query- param($_) } $query- param(); print Dumper( %fromweb); In this case, you
          Message 4 of 9 , Sep 11, 2006
          • 0 Attachment
            For you debug your code, try this:

            use Data::Dumper;
            my %fromweb = map { $_ => $query->param($_) } $query->param();
            print Dumper(\%fromweb);

            In this case, you will see all pairs (name, value) sended by POST method.
            HTH.

            ballast_boy escreveu:
            >
            > Here is the form:
            >
            > <body>
            > <FORM METHOD="POST" ACTION="/cgi-bin/userchk.cgi">
            > <div align="center">
            > <p>UserName:
            > <INPUT TYPE="text" NAME="name">
            > <br />
            > <BR>
            > Password:
            > <INPUT TYPE="password" NAME="pass">
            > <BR>
            > </p>
            > <p align="center">
            > <INPUT TYPE="SUBMIT" VALUE="Submit">
            > </p>
            > </div>
            > </FORM>
            >
            > </body>
            > </html>
            >
            > I'm lost.
            >
            > William
            >
            > --- In perl-beginner@yahoogroups.com
            > <mailto:perl-beginner%40yahoogroups.com>, tnas <nascimentothiago@...>
            > wrote:
            > >
            > > Did you check if the parameters from the POST are with a defined
            > value ?
            > >
            > > ballast_boy escreveu:
            > > >
            > > > I still can't get it to write to file. Here is all the code;
            > > >
            > > > #!/user/bin/perl -w
            > > > use CGI qw(param);
            > > > $query = new CGI;
            > > > print $query->header;
            > > >
            > > > open (USERINFO, ">/home/tomcat/passchk/userinfo.txt") or
            > > > die "Cannot open /home/tomcat/passchk/userinfo.txt : $!";
            > > >
            > > > print USERINFO param("name"), param("pass");
            > > > close (USERINFO);
            > > >
            > > > That's it. Short and should be simple. I know I'm missing
            > > > something that should be easy but I just can't spot it.
            > > >
            > > > Thanks for all the advice,
            > > >
            > > > William
            > > >
            > > > --- In perl-beginner@yahoogroups.com
            > <mailto:perl-beginner%40yahoogroups.com>
            > > > <mailto:perl-beginner%40yahoogroups.com>, merlyn@ wrote:
            > > > >
            > > > > >>>>> "ballast" == ballast boy <ballast_boy@> writes:
            > > > >
            > > > > ballast> Help! I'm new to perl but I have gotten some things
            > > > down. I know how
            > > > > ballast> to open and read files. I've got a form on the web
            > that
            > > > I can get
            > > > > ballast> information from and either print it at my Unix
            > screen or
            > > > back to the
            > > > > ballast> web. Here's my problem. How do you get info from a
            > form
            > > > (I use Post
            > > > > ballast> as method) and write it to a text file on my server?
            > Yes
            > > > the file is
            > > > > ballast> writable. Here is what I have;
            > > > > ballast> (usual perl stuff here)
            > > > > ballast> print $query->header;
            > > > >
            > > > > ballast> $query->param('name');
            > > > > ballast> $query->param('pass');
            > > > >
            > > > > ballast> #I need to write it to here****
            > > > >
            > > > > ballast> open (UserInfo, '>/home/tomcat/passchk/userinfo.txt');
            > > > >
            > > > > Always use the "open ... or die" idiom.
            > > > >
            > > > > ballast> Looks simple but I have tried eveything and can't get
            > it
            > > > to work. I'm
            > > > > ballast> afraid either my computer, Larry Wall or myself is
            > going
            > > > to get hurt
            > > > > ballast> if I don't figure this out soon ;)
            > > > >
            > > > > If you just want to print those two params into the file:
            > > > >
            > > > > use CGI qw(param); # I hate typing $query->param everywhere
            > > > > open OUTFILE, ">/my/output/file" or die "Cannot
            > > > create /my/output/file: $!";
            > > > > print OUTFILE param("name"), param("pass");
            > > > > close OUTFILE;
            > > > > ... rest of CGI output has to happen here ...
            > > > >
            > > > > However, you'll probably want some sort of delimiter around
            > the two
            > > > > values. Keep in mind that every possible character could be
            > coming
            > > > > in from these params, so either regex-clean them first, or use
            > a
            > > > storage
            > > > > system that can delimit any possible character.
            > > > >
            > > > > --
            > > > > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1
            > 503
            > > > 777 0095
            > > > > <merlyn@> <URL:http://www.stonehenge.com/merlyn/
            > <http://www.stonehenge.com/merlyn/>
            > > > <http://www.stonehenge.com/merlyn/
            > <http://www.stonehenge.com/merlyn/>>>
            > > > > Perl/Unix/security consulting, Technical writing, Comedy, etc.
            > etc.
            > > > > See PerlTraining.Stonehenge.com for onsite and open-enrollment
            > > > Perl training!
            > > > >
            > > >
            > > >
            > >
            > > --
            > > Thiago Nascimento
            > > #!/usr/bin/perl
            > > $_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while s/(..)
            > (.)//;print substr$_,1,1;
            > >
            >
            >

            --
            Thiago Nascimento
            #!/usr/bin/perl
            $_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while s/(..)(.)//;print substr$_,1,1;
          • ganthimathi
            Hai , U can get the Value by use CGI qw(:standard); $Name =param(name); the sample code as below, #!/usr/bin/perl use CGI qw(:standard); print Content
            Message 5 of 9 , Sep 13, 2006
            • 0 Attachment
              Hai ,

              U can get the Value by
              use CGI qw(:standard);
              $Name =param(name);

              the sample code as below,



              #!/usr/bin/perl

              use CGI qw(:standard);
              print "Content Type:text/html\n\n";

              $Name=param(name);
              if($Name)
              {
              print " Name Typed By you is :: $Name";
              }
              print qq!
              <html>
              <title> Sample </title>
              <body>
              <FORM Method=POST >
              <div align="center">
              <p>UserName:
              <INPUT TYPE="text" NAME=name>
              <br> <BR> Password:
              <INPUT TYPE=password NAME=pass>
              <BR> <p align="center">
              <INPUT TYPE="SUBMIT" VALUE="Submit">
              </p>
              </div>
              </FORM>
              </body>
              </html>!;


              --Mathi

              ballast_boy wrote:

              >Here is the form:
              >
              ><body>
              ><FORM METHOD="POST" ACTION="/cgi-bin/userchk.cgi">
              > <div align="center">
              > <p>UserName:
              > <INPUT TYPE="text" NAME="name">
              > <br />
              > <BR>
              > Password:
              > <INPUT TYPE="password" NAME="pass">
              > <BR>
              > </p>
              > <p align="center">
              > <INPUT TYPE="SUBMIT" VALUE="Submit">
              > </p>
              > </div>
              ></FORM>
              >
              ></body>
              ></html>
              >
              >I'm lost.
              >
              >William
              >
              >--- In perl-beginner@yahoogroups.com, tnas <nascimentothiago@...>
              >wrote:
              >
              >
              >>Did you check if the parameters from the POST are with a defined
              >>
              >>
              >value ?
              >
              >
              >>ballast_boy escreveu:
              >>
              >>
              >>>I still can't get it to write to file. Here is all the code;
              >>>
              >>>#!/user/bin/perl -w
              >>>use CGI qw(param);
              >>>$query = new CGI;
              >>>print $query->header;
              >>>
              >>>open (USERINFO, ">/home/tomcat/passchk/userinfo.txt") or
              >>>die "Cannot open /home/tomcat/passchk/userinfo.txt : $!";
              >>>
              >>>print USERINFO param("name"), param("pass");
              >>>close (USERINFO);
              >>>
              >>>That's it. Short and should be simple. I know I'm missing
              >>>something that should be easy but I just can't spot it.
              >>>
              >>>Thanks for all the advice,
              >>>
              >>>William
              >>>
              >>>--- In perl-beginner@yahoogroups.com
              >>><mailto:perl-beginner%40yahoogroups.com>, merlyn@ wrote:
              >>>
              >>>
              >>>>>>>>>"ballast" == ballast boy <ballast_boy@> writes:
              >>>>>>>>>
              >>>>>>>>>
              >>>>ballast> Help! I'm new to perl but I have gotten some things
              >>>>
              >>>>
              >>>down. I know how
              >>>
              >>>
              >>>>ballast> to open and read files. I've got a form on the web
              >>>>
              >>>>
              >that
              >
              >
              >>>I can get
              >>>
              >>>
              >>>>ballast> information from and either print it at my Unix
              >>>>
              >>>>
              >screen or
              >
              >
              >>>back to the
              >>>
              >>>
              >>>>ballast> web. Here's my problem. How do you get info from a
              >>>>
              >>>>
              >form
              >
              >
              >>>(I use Post
              >>>
              >>>
              >>>>ballast> as method) and write it to a text file on my server?
              >>>>
              >>>>
              >Yes
              >
              >
              >>>the file is
              >>>
              >>>
              >>>>ballast> writable. Here is what I have;
              >>>>ballast> (usual perl stuff here)
              >>>>ballast> print $query->header;
              >>>>
              >>>>ballast> $query->param('name');
              >>>>ballast> $query->param('pass');
              >>>>
              >>>>ballast> #I need to write it to here****
              >>>>
              >>>>ballast> open (UserInfo, '>/home/tomcat/passchk/userinfo.txt');
              >>>>
              >>>>Always use the "open ... or die" idiom.
              >>>>
              >>>>ballast> Looks simple but I have tried eveything and can't get
              >>>>
              >>>>
              >it
              >
              >
              >>>to work. I'm
              >>>
              >>>
              >>>>ballast> afraid either my computer, Larry Wall or myself is
              >>>>
              >>>>
              >going
              >
              >
              >>>to get hurt
              >>>
              >>>
              >>>>ballast> if I don't figure this out soon ;)
              >>>>
              >>>>If you just want to print those two params into the file:
              >>>>
              >>>>use CGI qw(param); # I hate typing $query->param everywhere
              >>>>open OUTFILE, ">/my/output/file" or die "Cannot
              >>>>
              >>>>
              >>>create /my/output/file: $!";
              >>>
              >>>
              >>>>print OUTFILE param("name"), param("pass");
              >>>>close OUTFILE;
              >>>>... rest of CGI output has to happen here ...
              >>>>
              >>>>However, you'll probably want some sort of delimiter around
              >>>>
              >>>>
              >the two
              >
              >
              >>>>values. Keep in mind that every possible character could be
              >>>>
              >>>>
              >coming
              >
              >
              >>>>in from these params, so either regex-clean them first, or use
              >>>>
              >>>>
              >a
              >
              >
              >>>storage
              >>>
              >>>
              >>>>system that can delimit any possible character.
              >>>>
              >>>>--
              >>>>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1
              >>>>
              >>>>
              >503
              >
              >
              >>>777 0095
              >>>
              >>>
              >>>><merlyn@> <URL:http://www.stonehenge.com/merlyn/
              >>>>
              >>>>
              >>><http://www.stonehenge.com/merlyn/>>
              >>>
              >>>
              >>>>Perl/Unix/security consulting, Technical writing, Comedy, etc.
              >>>>
              >>>>
              >etc.
              >
              >
              >>>>See PerlTraining.Stonehenge.com for onsite and open-enrollment
              >>>>
              >>>>
              >>>Perl training!
              >>>
              >>>
              >>>
              >>>
              >>>
              >>--
              >>Thiago Nascimento
              >>#!/usr/bin/perl
              >>$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while s/(..)
              >>
              >>
              >(.)//;print substr$_,1,1;
              >
              >
              >
              >
              >
              >
              >
              >
              >Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
              >Yahoo! Groups Links
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >



              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.