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

In reply to Re: Trouble getting CGI parameters by japhy
in thread Trouble getting CGI parameters by gitarwmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.