PLZ HELP 
Author Message
 PLZ HELP

Hello,

What is wrong with this?

#!/usr/local/bin/perl

require "subparseform.lib";
&Parse_Form;
print "Content-type: text/html\n\n";

if ($ENV{'QUERY_STRING'} eq "new") {
&newuser;

Quote:
}

sub newuser {
$user = $formdata{'user'};
$email = $formdata{'email'};
$password = $formdata{'password'};
$money = "100";
$ufile = $user . ".txt";

   if (-e /members/$ufile) {
        print "Sorry, Someone already has registered the username :
$user";
          }
else {
#    CREATE NEW USER'S FILE
    OPEN (NEW,">>/members/$user.txt") || &Error;
     PRINT NEW "$user\n";
     PRINT NEW "$email\n";
     PRINT NEW "$password\n";
     PRINT NEW "$money\n";
    CLOSE (NEW);
#    SEND NEW USER A EMAIL MESSAGE
    OPEN (NEWMAIL, "|/usr/sbin/sendmail -t") || &Error;
     print NEWMAIL "To: $email\nFrom: ADMIN\n";
     print NEWMAIL "Subject: Your new Account\n";
     print NEWMAIL "Thanks for signing up";
    CLOSE (NEWMAIL);
 print "You are in";

Quote:
}
}

sub Error {
print "The Error is with the status of the files , or senmdmail";

Quote:
}

--

-------------------------------------------------------
| TBE: http://www.*-*-*.com/                      |
| * 3:2 Ratio + 100 Free credits! *                   |
| Tim's Chat Doors: http://www.*-*-*.com/ ~mundy/  |
-------------------------------------------------------



Wed, 28 Nov 2001 03:00:00 GMT  
 PLZ HELP

Quote:
> Hello,

> What is wrong with this?

> #!/usr/local/bin/perl

 Missing -w on that .
 and you should probably be using 'use strict;'

Quote:
> require "subparseform.lib";
> &Parse_Form;
> print "Content-type: text/html\n\n";

> if ($ENV{'QUERY_STRING'} eq "new") {
> &newuser;
> }

This doesnt do what you appear to think it does - you probably want
something like :
  if($formdata{'action'} eq 'new' )
    {
          &newuser;
        }

Of course I dont know what is going on inside your subparseform.lib
and also dont know what your form looks like - so 'action' may not
be right but you can work it out - and no please dont post your form or
your library.

Quote:

> sub newuser {
> $user = $formdata{'user'};
> $email = $formdata{'email'};
> $password = $formdata{'password'};
> $money = "100";
> $ufile = $user . ".txt";

>    if (-e /members/$ufile) {

The file path there is a bare word you should enclose it in double quotes.
Here and in the other place you use the fullpath to a file then you need
to be sure that this is the actual path to the file as seen by your program.
If your URL is http://www.blah.com/ and you want the files created under
the document root in a directory called 'members' then it is unlikely that
the actual path is /members/file.txt - it is more likely to be something
for example : /usr/www/share/username/members/ - but you will have to ask
your ISP about that.

Quote:
>         print "Sorry, Someone already has registered the username :
> $user";
>           }
> else {
> #    CREATE NEW USER'S FILE
>     OPEN (NEW,">>/members/$user.txt") || &Error;

Perl is case-sensitive - you want to use 'open' not OPEN
If you are creating a new file you only need one > .

Quote:
>      PRINT NEW "$user\n";
>      PRINT NEW "$email\n";
>      PRINT NEW "$password\n";
>      PRINT NEW "$money\n";
>     CLOSE (NEW);
> #    SEND NEW USER A EMAIL MESSAGE
>     OPEN (NEWMAIL, "|/usr/sbin/sendmail -t") || &Error;

Perl is case-sensitive - you want to use 'open' not OPEN

Quote:
>      print NEWMAIL "To: $email\nFrom: ADMIN\n";
>      print NEWMAIL "Subject: Your new Account\n";

You are missing a '\n' between your header and the body of your message -
you will probably get an error from sendmail ...

Quote:
>      print NEWMAIL "Thanks for signing up";
>     CLOSE (NEWMAIL);

... except you didnt check the return of this close so you dont know whether
sendmail has worked or not.

Quote:
>  print "You are in";
> }
> }

> sub Error {
> print "The Error is with the status of the files , or senmdmail";
> }

In both cases where you use this there is no point in going on - you
either have no filehandle to write to or no sendmail process to write
to you should think about how to terminate your program cleanly without
sending a confusing message to the user.

Also you output a 'text/html' but do not actuall print any HTML - although
that is a quibble.

You probably want to look at the CGI FAQ at :

   <http://www.webthing.com/tutorials/cgifaq.html>

Any how here is my rendering of the program using the module CGI.pm and
fixing all of the above points and others:

#!/usr/bin/perl  -w

use CGI qw(:standard);
use strict;

# these are local values for me

my $mail_prog = '/usr/lib/sendmail -t';
my $filepath  = '/usr/local/apache/htdocs/members/';

my %dispatch = (
                 'new' => \&newuser
                           );

print header(),start_html("Your title here");

if ( my $action = param('action'))
  {
    if (exists $dispatch{$action} )
          {
             &{$dispatch{$action}};
          }
        else
          {
             print "Invalid action";
          }
   }
else
  {
    print "No action specified"
  }

print end_html;

sub newuser
{
   my $user     = param('user');
   my $email    = param('email');
   my $password = param('password');
   my $money    = 100;

   my $ufile = $filepath . $user . '.txt';

   if (-e $ufile )
     {
        print "Sorry, Someone already has registered the username : $user";
     }
   else
    {
    if( open (NEW,">$ufile") )
          {
        print NEW join "\n" => ($user,$email,$password,$money);
                print NEW "\n";
        close (NEW);

        if( open (NEWMAIL, "|$mail_prog"))
          {
            print NEWMAIL <<EOMAIL;
To: $email
From: ADMIN
Subject: Your new Account

Dear $user,
Thanks for signing up
EOMAIL
            close (NEWMAIL);
              }
        print "You are in";
      }
        else
          {
            print "An error has occurred please contact the administrator";
          }
   }

Quote:
}

/J\
--

Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


Thu, 29 Nov 2001 03:00:00 GMT  
 PLZ HELP

Quote:

> Subject: PLZ HELP

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

Quote:
> What is wrong with this?

It isn't cut down to a minimal example showing what behavior of Perl
doesn't meet your expectations, for one thing. Cheers!

--
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



Thu, 29 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DBM question plz help

2. Plz help: Modifying server-side text files

3. Problems with pattern matching plz help.

4. perl questions-urgent plz help

5. Newbie matching problem- plz help

6. Plz help a newbie add up elements of an array

7. Can someone plz help me?

8. plz help me !!!!!!

9. Plz help - Perl Q

10. Pb with regular expression plz help

11. plz help about using DLL w/ perl

12. I thought i had this right, plz help

 

 
Powered by phpBB® Forum Software