Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple write to file won't work :(

Status
Not open for further replies.

xiaoleiqq

Programmer
Aug 30, 2006
43
US
Below are the script...
It works on the shell, but won't work from a web browser, I think probably the permission issue?

Thank you in advance

#!/usr/bin/perl
#
# final

use CGI;
use strict;

my $a = new CGI;
my $email;

print $a->header();
print $a->start_html(-title =>"order");

print qq(Ordering process is finalized, <br><br>);
$email = $a->param('email');
my $filename = "emailRec.txt";

open(FILEHANDLE,">>", $filename);
print FILEHANDLE "$email";
close(FILEHANDLE);

print "<br>email recorded<br>";
print $a->end_html();
 
first, change $a to something else, like $q or $cgi. $a is a package global (as is $b) and should not be used as a private variable declared with 'my'. Test all system functions for failure, an easy way is to use "die":

Code:
open(FILEHANDLE,">>", $filename) or die "Can't open $filename: $!";

$! will return the operating sytem error that caused the failure.

"Won't work in the browser" means nothing. What isn't working? What happens? Any error messages in the server logs?
 
Thank you for your help, I am off work right now, and I will change it tonight and see what happens.

 
I check the log and the error is file cannot be open,

then I go around create the file first, then the script works.

my guess is when I called this script from web-browser, It just cannot create the file.

Again, thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top