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!

stumped on premature end of script headers

Status
Not open for further replies.

ElectusUnum

Technical User
May 24, 2002
16
0
0
US
I know this is a newby problem, but I'm really stumped. Can some kind soul help? I wrote this program to write HTML form data to a text file (for my counter-strike gaming "clan") . Everything goes fine, the text is written to the file. It executes fine using perl at the command line (windows xp). The only problem is, after I hit submit (and the data is written!) I get the evil "premature end of script headers message"! The html is at

#! C:/perl/bin/perl.exe -w

use strict;
use CGI qw:)all);
use Fcntl qw:)flock);

#Location of text file
my $text="c:/web/http/apache2/htdocs/blam/admin/applications.txt";

open(TXT, ">>$text");
print TXT "Name: ", param('name'), "\n";
print TXT "Email: ", param('email'), "\n";
print TXT "Why I want to be in BLAM!:\n ", param('why'), "\n";
print TXT "\n\n\n___________\n\n\n";
close(TXT);
 
Try this bit of code it might do the trick. Have changed the location of the $text variable, you might need to tweak this a bit to get it just right.

#! C:/perl/bin/perl.exe -w

use strict;
use CGI qw:)all);
use Fcntl qw:)flock);
my $q = new CGI;
#Location of text file
my $text="../blam/admin/applications.txt";

open(TXT, ">>$text");
print TXT "Name: ", param('name'), "\n";
print TXT "Email: ", param('email'), "\n";
print TXT "Why I want to be in BLAM!:\n ",('why'), "\n";
print TXT "\n\n\n___________\n\n\n";
close(TXT);

print $q->header(),
$q->start_html(),
$q->table({-border=>'1',
-bordercolor=>'black',
-align=>'center'},
$q->Tr(
$q->td('Thank you for wanting to join BLAM')
)
),
$q->end_html;
 
Your problem is that the web server expects the CGI code to produce a valid http header to return to the request.

General flow
1 - Client (browser) sends an http reqeust to the web server
2 - web server fires the CGI code
3 - CGI code builds an appropriate http header and output
4 - web server passes that output back to the client

In your code, there is nothing producing a valid header or html output (I assume you will shoot a little html back at the browser to confirm the action).

The code beatzin added to your code does just that, it
print $q->header(), # creates a header
$q->start_html(), # starts the html output
$q->table({-border=>'1', # starts a table
-bordercolor=>'black',
-align=>'center'},
$q->Tr(
$q->td('Thank you for wanting to join BLAM')
)
),
$q->end_html; # closes the html


'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I think i need to be more verbose in my explanations. goBoating says it how it is.
 
Thank you guys so much, I'm not new to perl, but I am to CGI, and I haven't written any perl stuff in a year or so :^/ . Again, thanks a lot, and it all makes sense now( I should of known about the headers *smacks forehead*, lol)
-Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top