Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Nothing is being written into my opt-in.txt file

by bgatto (Initiate)
on Jul 10, 2013 at 20:39 UTC ( #1043558=perlquestion: print w/replies, xml ) Need Help??

bgatto has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I'm running an HTML form on a web hostthat looks like this:

<form method=POST action=" +gi"> <b><font face="arial" size=5 color="#ffffff"> Name: <input type="text" name="fullname" size=35><br> &nbsp;eMail: <input type="text" name="email" size=35> </b></font> <p align="center"><input type="submit" name="submit" background="#ffff +00" value="Get It Now" style="font:24pt Arial Black; color:#0000FF;"> +</p> </form>

The code for sendinfo.cgi is:

#!/usr/bin/perl -w use strict; my $sendto = param('email'); my $sendname = param('name'); open (LOG, ">>") || die("Erro +r: " . $!); print LOG $sendname . "," . $sendto . \n; close (LOG);

When I enter my name and email address and click the submit button, I get sent back to the original web site and I get an error. When I go and check the opt-in.txt file, I find nothing in the file. What is going wrong?

Replies are listed 'Best First'.
Re: Nothing is being written into my opt-in.txt file
by Illuminatus (Curate) on Jul 10, 2013 at 20:57 UTC
    1. Your html says 'fullname', but your script is looking for just 'name'
    2. Can you run sendinfo.cgi on the server (modified to take it's params from the cmdline) and have it do what you expect?
    3. If (2) works, make sure the user the webserver is running your script as has permission to do what you want


Re: Nothing is being written into my opt-in.txt file
by thomas895 (Deacon) on Jul 10, 2013 at 22:55 UTC

    You're all missing the root of the problem:

    open (LOG, ">>") || die("Erro +r: " . $!);

    Something there is wrong, but can you see it?

    "Excuse me for butting in, but I'm interrupt-driven..."

      Excellent, and the second thing that is wrong is failure to check the server logs, where STDERR would have recorded the die message.


Re: Nothing is being written into my opt-in.txt file
by hippo (Bishop) on Jul 10, 2013 at 21:31 UTC

    Your code doesn't compile:

    $ perl -cw /tmp/ Bareword "n" not allowed while "strict subs" in use at /tmp/ l +ine 9. /tmp/ had compilation errors.

    Haven't we been through this before? Why did you not try to compile the script yourself? Why did you not try looking in the error log?

Re: Nothing is being written into my opt-in.txt file
by poj (Abbot) on Jul 10, 2013 at 21:42 UTC
    Use this as your cgi, it will show you what is wrong
    #!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $sendto = param('email'); my $sendname = param('fullname'); #my $logfile = ''; my $logfile = '/tmp/opt-in.txt'; my $msg; if ( open LOG, '>>',$logfile ) { print LOG "$sendname,$sendto\n"; close (LOG); $msg = "$sendname $sendto written to $logfile"; } else { $msg = "File open Error: ".$!; } print header(),start_html() ,p($msg) ,a({-href=>'easy.html'},'return') ,end_html();

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1043558]
Approved by davido
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2022-05-24 16:37 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (84 votes). Check out past polls.