55 users online (1 members and 54 guests)  


  Results 1 to 4 of 4

Related

  1. Perl commands in an input file to cgi script    Forum: CGI Perl Forum
    Replies: 0
  2. Problem with excel file writing using PERL    Forum: CGI Perl Forum
    Replies: 0
  3. Cross browser ticker from text file needed    Forum: Website Scripts Forum
    Replies: 0
  4. Writing to text file problem    Forum: CGI Perl Forum
    Replies: 5
  5. CGI form input doesn't write to text file    Forum: CGI Perl Forum
    Replies: 2
  1. #1
    rustix's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Posts
    2

    Question Help needed with writing user input to a text file using Perl and CGI. Help ASAP!

    Hi.. I'm creating a new user registration page (like the ones you find when you register on a forum) using Perl (that is with CGI). As I have to store the new user's information I decided to write the user's information to a text file stored on the server. The following is the coding i used to write the information to a text file. There are 5 input boxes the values of which i want it written to the text file:
    1. Name
    2. Username
    3. Password
    4. Confirm Password
    5. Date of Birth
    code used to save the information:


    Code:
    #!c:\Perl\bin\Perl.exe
    $file = "registration.txt";
    $formdata = $ENV{'QUERY_STRING'};
    ($name, $username) = split(/=/,$formdata);
    
    print "Content-Type: text/html\n\n";
    print "<html>";
    print "<body>";
    print "Hello $name";
    print "</body></html>";
    
    if (open (OUTFILE, "> $file"))
    {
        print OUTFILE "name = $name\n";
    }
    However i only seem to be able to save the name of the user (basically only the first variable). How could I store the rest?

    Are there any suggestions or improvements that could be recommended?

    All help is greatly appreciated asap.
    Thanks in advance....

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Help needed with writing user input to a text file using Perl and CGI. Help ASAP!

    If I were to perform the same task as you, I would do it like this assuming I am using a HTML Form to submit the data. Your script looks much more like perl than CGI.
    HTML Form
    Code:
    <form action="script.pl" method="post">
    <p>Name:<input type="text" name="name" value="">
    <p>Username:<input type="text" name="username" value="">
    <p>Password:<input type="text" name="password" value="">
    <p>Confirm Password:<input type="text" name="confirm_password" value="">
    <p>Date Of Birth:<input type="text" name="date_of_birth" value="">
    <input type="submit" name="submit" value="Submit">
    <form>
    Perl
    Code:
    #!c:\Perl\bin\Perl.exe
    
    my $file = "registration.txt";
    my $name = param('name');
    my $username = param('username');
    my $password = param('password');
    my $confirm_password = param('confirm_password');
    my $date_of_birth = param('date_of_birth');
    
    print "Content-Type: text/html\n\n";
    print "<p>Hello $name";
    print "<p>Username: $username, Password: $password";
    print "<p>DoB - $date_of_birth";
    
    open (LOG, ">$file") || die "D";
    flock (LOG, 2) || die "D";
    print LOG "$name, $username, $password, $date_of_birth";
    close (LOG);
    Chris

  3. #3
    rustix's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Posts
    2

    Re: Help needed with writing user input to a text file using Perl and CGI. Help ASAP!

    what does LOG do?

  4. #4
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Help needed with writing user input to a text file using Perl and CGI. Help ASAP!

    LOG is simply the file handle. The same as OUTFILE in your code.
    Chris



Tags for this Thread