[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ot perl help request



Hi Justin,

I'm having a hard time understanding your script. What's the deal with
'Q' and import_data ?

__BEGIN_REWRITE__
#!/usr/bin/perl -w

use strict; # helps ; must declare varibles
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $OUTPAGE = '/thankyou.html';
my $ERR = '/error.html';

my $DATAFILE = 'bla.txt';

# define $q as an instance of an CGI object:
# ORIGINAL: my $cgi = new CGI;

my $q = CGI->new();

# I didn't see this in the man page, but if you're trying to get
# parameters from the query string then use param as in from
# <form method="GET"><input type="text" name="name"/></form>
# or POST - both work for param

# ORIGINAL:
# $cgi->import_data('Q');

my $name           = $q->param("name");
my $email          = $q->param("email");
my $menu           = $q->param("menu");
my $remote_address = $ENV{REMOTE_ADDR};

open (DATA, ">> $DATAFILE");
print DATA $name, $email, $menu, $remote_address, "\n";
close DATA;

if(defined($name) && $name ne "") {
  print $q->redirect(-location=>$ERR);
} else {
  print $q->redirect(-location=>$OUTPAGE);
}  
__END_REWRITE__

hth Elizabeth

"justin cunningham" <jcunningham@engine8.com> writes:

> Hello, I'm trying to get this script to do error checking but it prints
> the error page every time regardless if there is or isn't input data.
> It works ok without the if statement but I wanted it to do the
> errorchecking.  I spent a good amount of time trying to figure this out
> on my own before emailing the list but I've learned perl is pretty
> unforgiving when you have a misplace character or two.  
> 
> Thanks for any help on this.
> 
> justin
> 
> #!/usr/bin/perl 
> use CGI;
> 
> $OUTPAGE = '/thankyou.html';
> $DATAFILE = 'bla.txt';
> $ERR = '/error.html';
> 
> my $cgi = new CGI;
> $cgi->import_data('Q');
> 
> open (DATA, ">> $DATAFILE");
> print DATA qq|$Q::name, $Q::email, $Q::menu, $ENV{REMOTE_ADDR}\n|; close
> DATA;
> 
> if  ($Q::{"name"} ne "") {
> print $cgi->redirect(-location=>$ERR= '/error.html');
> }
> 
> else {
> print $cgi->redirect(-location=>$OUTPAGE= '/thanks.html');
> }  
> 
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


-- 
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: