in reply to Re^2: HTTP headers and redirection
in thread HTTP headers and redirection

In reading your responses to the posts, I'm not sure if you solved your problem.

What you need to do is remove this line (line 2 or 3)
print "Content-type: text/html\n\n";

and put it after the last else, just before
print "<HTML>\n";

Replies are listed 'Best First'.
Re^4: HTTP headers and redirection
by student (Novice) on Nov 11, 2004 at 16:49 UTC
    I moved it and it still doesn't work...this is getting frustrating. If I leave my print location line at the top it gives me a page could not be displayed. When I leave it like it is below it gives me an internal server error. Any ideas?
    #!c:\phpdev\perl\bin\perl.exe use CGI qw(:standard -debug); #prevent Perl from creating undeclared variables use strict; #declare variables my ($Salesperson, $Sales, $Size, $Rate, $Percentage, @records, @errors +, $errors, $bonus); #assign input items to variables $Salesperson = param('Salesperson'); $Sales = param('Sales'); $Rate = param('Rate'); $Percentage = param('Percentage'); #calculate bonus rates $bonus = $Rate * $Sales; if ($Salesperson eq "") { print "Location: http://localhost/cgi-bin/c12ex3b.html\n\n"; } elsif ($Sales == "") { print "Location: http://localhost/cgi-bin/c12ex3b.html\n\n"; } elsif ($Rate == "") { print "Location: http://localhost/cgi-bin/c12ex3b.html\n\n"; } else { print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<HEAD><TITLE>Patton Industries</TITLE><BASEFONT SIZE=5></HEAD>\ +n"; print "<H1>Bonus Calculation</H1>\n"; print "<BODY>\n"; print "Salesperson: $Salesperson<BR>\n"; printf "Your bonus is: \$%.2f<BR><BR>\n", $bonus; printf "You entered a sales amount of \$%.2f and a \n", $Sales; printf "bonus rate of %.1f%%.<BR>\n", $Rate * 100; print "</BODY>\n"; print "</HTML>\n"; print "</BODY></HTML>\n"; }
Re^4: HTTP headers and redirection
by nedals (Deacon) on Nov 11, 2004 at 17:31 UTC

    Student,
    The last set of code you posted is correct and should not give a fatal error.

    Add this line after your 'use CGI'
    use CGI::Carp(qw/fatalsToBrowser/);

    That will print the error to your browser to easily identify the problem.

      Thanks to all who gave input. I know this isn't the perfect way to make this script work, but it does. What does everyone think?? I'm a novice. Could you critique so I can get a better handle on this?
      #!/usr/bin/perl use CGI qw(:standard -debug); #prevent Perl from creating undeclared variables use strict; #declare variables my ($Salesperson, $Sales, $Size, $Rate, $Percentage, @records, @errors +, $errors, $bonus); #assign input items to variables $Salesperson = param('Salesperson'); $Sales = param('Sales'); $Rate = param('Rate'); $Percentage = param('Percentage'); #calculate bonus rates $bonus = $Rate * $Sales; if ($Salesperson eq "" or $Sales == "" or $Rate == ""){ print "Location: http://carrotcake.nsm.tridenttech.edu/c12ex3b +.html\n\n"; } elsif ($Sales == "") { print "Location: http://carrotcake.nsm.tridenttech.edu/c12ex3b +.html\n\n"; } elsif ($Rate == "") { print "Location: http://carrotcake.nsm.tridenttech.edu/c12ex3b +.html\n\n"; } else { print "Content-tuype: text/html\n\n"; print "<HTML>\n"; print "<HEAD><TITLE>Patton Industries</TITLE><BASEFONT SIZE=5></HEAD>\ +n"; print "<H1>Bonus Calculation</H1>\n"; print "<BODY>\n"; print "Salesperson: $Salesperson<BR>\n"; printf "Your bonus is: \$%.2f<BR><BR>\n", $bonus; printf "You entered a sales amount of \$%.2f and a \n", $Sales; printf "bonus rate of %.1f%%.<BR>\n", $Rate * 100; print "</BODY>\n"; print "</HTML>\n"; print "</BODY></HTML>\n"; }