|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
newbie with form problem
Hi all-
I'm a major newbie and I'm trying to get a simple form to work. I just wanna gather info and record it into a text file. Here's the script: #!/usr/bin/perl -w use strict; use CGI qw(:standard); $target="http://www.mysite.com/thankyou.html"; print header; open (ALLUSERS, ">>/c5/jmpservemaillist.txt") || die "cannot open mydatafile: $!\n";open mydatafile: $!\n"; print ALLUSERS scalar (localtime)"^", "$fname^", "$lname^", "$firm^", "$email", "\n"; close (ALLUSERS); print redirect( -uri=>$target ); And here's the error message I get: Global symbol "$target" requires explicit package name at /c5/jmpserv/cgi-bin/jmpemail.cgi line 8. String found where operator expected at /c5/jmpserv/cgi-bin/jmpemail.cgi line 13, near ")"^"" (Missing operator before "^"?) syntax error at /c5/jmpserv/cgi-bin/jmpemail.cgi line 13, near ")"^"" Global symbol "$fname" requires explicit package name at /c5/jmpserv/cgi-bin/jmpemail.cgi line 13. Global symbol "$lname" requires explicit package name at /c5/jmpserv/cgi-bin/jmpemail.cgi line 13. Global symbol "$firm" requires explicit package name at /c5/jmpserv/cgi-bin/jmpemail.cgi line 13. Global symbol "$email" requires explicit package name at /c5/jmpserv/cgi-bin/jmpemail.cgi line 13. /c5/jmpserv/cgi-bin/jmpemail.cgi had compilation errors. I'd appreciate any help. |
|
#2
|
|||
|
|||
|
uh, strict momma
Since you are doing: use strict;
You must declare variables before you use them. Read some documentation on "use strict;" An example would be this: instead of $target = "http://targeturl.com"; you would do my $target = "http://targeturl.com"; and for $fname and all of your other variables you must declare them first by simple doing: my $fname; my $lname; That is the whole purpose behind strict is forcing you to declare things before you use them that way it eliminates alot of errors. If you want a good tutorial on strict, go to www.perlmonks.org and search for: use strict Hope this helps, DKode
__________________
"Mankind cannot define memory, yet it defines mankind" |
|
#3
|
|||
|
|||
|
dkode-
Thanks, momma. Like I said, I'm a total newbie. You are the m$#*& f@*&%'in man. Thank you. |
|
#4
|
|||
|
|||
|
problem with redirection
Okay, I've got the script to work except for the redirection to a new page. The script does not work with the redirection bit in there. If I take it out it runs fine. Why won't the redirection work?
#!/usr/bin/perl -w use strict; use CGI qw(:all); use diagnostics; my $fname=param('fname'); my $lname=param('lname'); my $firm=param('firm'); my $email=param('email'); my $target="http://www.mysite.com/thankyou.html" print header; open (ALLUSERS, ">>/c5/jmpserv/email.txt") || die "cannot open mydatafile: $!\n"; print ALLUSERS "$fname*", "$lname*", "$firm*", "$email", "\n"; close (ALLUSERS); print redirect( -uri => $target); |
|
#5
|
|||
|
|||
|
I'm not sure about the redirect with CGI.pm.
Normally when I want to redirect I just do: print "Location: http://url.to.redirect.to/\n\n"; And that will redirect them to that specific page. If you go to perldoc.com and search for cgi.pm you'll find what you need. Hope this helps! DKode |
|
#6
|
|||
|
|||
|
Thanks again, dkode.
|
|
#7
|
|||
|
|||
|
closed header?
Well, after looking around perlmonks it seems like a lot of people have had problems with redirection/location. I've put in the bit you told me but rather than redirect to the new page, the actual line of code is written. From what I gather this is happening because the header has already been closed. Is this correct? If so, what do I need to do to keep the header open and thus make the redirect work?
|
|
#8
|
|||
|
|||
|
Writhe,
The redirect command you're using should not be used along with the header. Try removing the "print header;" bit of code. Bob Reference |
|
#9
|
|||
|
|||
|
thanks, man
mullaney-
Wow. I was under the impression I had to print the header to get the data from the form. It is working great now. Thanks. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > newbie with form problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|