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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi feedback form

Status
Not open for further replies.

ailse

Programmer
Jan 20, 2004
79
0
0
GB
Hi All,

I have the following code which i'm trying out to make a feedback form:

Code:
#!/usr/bin/perl

use CGI;

# Create the CGI object
my $query = new CGI;

# Output the HTTP header
print $query -> header ( );


# Capture the form results

my $name = $query -> paranm("name");
my $email = $query -> param("email");
my $feedback = $query -> param("feedback");

# get data from fields and print to feedback text file

open (FEEDBACK, ">>feedback.txt");

print FEEDBACK "Name: $name\n";
print FEEDBACK "E-mail: $email\n";
print FEEDBACK "Feedback: $feedback\n\n\n";

close FEEDBACK;

but predictably it doesn't work... is there something else i need to do?

Also, i'd like to display a thank-you page to the user when they click "submit" - how would i go about doing that?

cheers :)
 
You have a typo here:

Code:
my $name = $query -> paranm("name");

its 'param', not 'paranm'

Outside of that is it failing silently or giving an error?

As for the 'thank you page', I would issue a redirect to a static page rather then print a header and embedded html.
 
corrected the typo and still the same problem... the error i get is "Premature end of script headers"...
 
I see this

Code:
print $query -> header ( );

which should be

Code:
print $query->header( );

What is your error log saying? Ibet it tells you exactly what line is busted.

 
ok i have modified my code to this now - think i might have been leaving some stuff out before:

Code:
#!/usr/bin/perl

use CGI;

# Create the CGI object
my $query = new CGI;

# Output the HTTP header
print $query -> header;

print $query -> start_html (-title => 'Feedback',
			    -BGCOLOR => 'white');

# Capture the form results

my $name = $query -> param("name");
my $email = $query -> param("email");
my $feedback = $query -> param("feedback");

# get data from fields and print to feedback text file

open (FEEDBACK, ">>feedback.txt");



print FEEDBACK "Name: $name\n";
print FEEDBACK "E-mail: $email\n";
print FEEDBACK "Feedback: $feedback\n\n\n";

print $query -> b($query -> font({-color=>'#993333', face=>verdana}, "test"));



close FEEDBACK;

print $query -> end_html;

is there any special syntax to use to print cgi output to file? I have put in a test print statement to see if just the html bits will work but i'm still getting the same server error as before...
 
don't know if this helps but i think i've narrowed it down to the bit of syntax i'm stuck on - i've pared down the code:

Code:
#!/usr/bin/perl

use CGI;
$query = new CGI;

open (FEEDBACK, ">>feedback.txt");

print $query -> header;
print $query -> start_html (-title => 'A Greeting');
#print "<h1> Hello ";
#print $query -> param('name');
#print "</h1>";

print FEEDBACK "Your name is $name";

print $query -> param('name');


print $query -> end_html;

the html form is created fine and the name is printed in the browser. however the bit i'm interested in, printing to the output file doesn't work...

any ideas?
 
yep done that, still doesn't print :( really can't figure out what's going wrong...
 
that is exactly what i've changed the permissions to... i have checked and rechecked the code a thousand time, and the permissions... really at a loss with this one :(
 
Maybe the server is configured not to allow scripts to write into the cgi-bin directory (which is, after all, a pretty bad idea).

Try putting your feedback.txt file someplace else - I suggest somewhere right outside your web space. Then use an absolute path to tell the script where it is, something like

[tt]/home/mydomain/secure/feedback.txt[/tt]

-- Chris Hunt
 
Do some debugging

Code:
open (FEEDBACK, ">>feedback.txt") || print  "COULD NOT OPEN OUTPUT FILE : $! $&";

That will tell you exactly what the problem opening the output file is.

The error log probably already has this info, you have not posted the contents of that yet and it is CRITICAL to helping you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top