Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Trouble getting CGI parameters

by japhy (Canon)
on May 01, 2006 at 00:00 UTC ( [id://546615]=note: print w/replies, xml ) Need Help??


in reply to Trouble getting CGI parameters

Your program does two things. It prints HTML output (a form you need to fill in) and then it appends to a data file. But you should only be appending to the data file after the form has been submitted. And your FORM tag has a very weird URL: "http://localhost/newuser.cgi?action=newuser?first?last" doesn't make a lot of sense. You probably just want "http://localhost/newuser.cgi".

Here is a simple program:

#!/usr/bin/perl use CGI; use CGI::Carp qw( fatalsToBrowser ); use strict; use warnings; my $query = CGI->new; # if we got here from a form being submitted, # do the adduser() stuff adduser($query) if $query->param; print << "END_HTML"; <html> <body> <form method="post" action="thisprogram.cgi"> Username: <input type="text" name="user"><br> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> Password: <input type="password" name="pass"><br> <input type="submit" value=" Add User "> </form> </body> </html> END_HTML sub add_user { my ($q) = @_; open PASSWD, ">> $passwd_file" or die "can't append to $passwd_file: $!"; print PASSWD join(":" => $q->param('first'), $q->param('last'), $q->param('user'), $q->para +m('pass') ), "\n"; close PASSWD; }

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://546615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found