By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

difficulty in accessing perl program through a html page

P: 1
Hi,

I am new to perl and was trying to write a perl program witha UI.
i.e. I have written a html form which invokes a perl program to execute and to print back the data selected in the form.

When i enter details into the html form and click on the submittal button, it throws an error saying
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, www@ophidian and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


--------------------------------------------------------------------------------

Apache/2.0.55 HP-UX_Apache-based_Web_Server (Unix) DAV/2 Server at ophidian.india.hp.com Port 8080 "

Below is the code of both the html and the perl script it calls.
Expand|Select|Wrap|Line Numbers
  1. html:
  2. <title>FORM 1</title>
  3. <html>
  4. <form method="POST" 
  5. action="http://ophidian.india.hp.com:8080/tools/newpro.pl">
  6. <p>
  7. <p>
  8. <table border=5 cellpadding=1 cellspacing=1><center>
  9. <tr>
  10. <th colspan=2>Submittal Management Tool</th>
  11. </tr>
  12. <tr>
  13. <td align=left><b>Release:</b></td>
  14. <td align=center>
  15. <select name ="release" size=4>
  16. <option>0706
  17. <option>0709
  18. <option>0712
  19. <option>0803
  20. <option>0809
  21. </select>
  22. </td>
  23. </tr>
  24.  
  25. <tr><td></td><td><center>
  26. <input type="reset" value="Clear">
  27. <input type="submit" value="Submit">
  28. </center></td></tr>
  29. </table>
  30. </center>
  31. </form>
  32. </html>
  33.  

Perl:
Expand|Select|Wrap|Line Numbers
  1. #!/opt/perl/bin/perl
  2.  
  3.  
  4. # The following accepts the data from the form and splits it into its component parts
  5.  
  6.  
  7.  
  8.         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  9.  
  10.         @pairs = split(/&/, $buffer);
  11.  
  12.         foreach $pair (@pairs)
  13.         {
  14.                 ($name, $value) = split(/=/, $pair);
  15.                 $value =~ tr/+/ /;
  16.                 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  17.                 $FORM{$name} = $value;
  18.         }
  19. print "<p>";
  20. print "<p>";
  21. print " u selecte rel: $FORM{Release}<p>";
  22. exit(0);
  23.  

Could anyone please tell me why i am getting this error?
Please help!
Jul 22 '08 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
You need to print an HTTP header before any other output. The simplest way is:

Expand|Select|Wrap|Line Numbers
  1. print "Content-type: text/html\n\n";

Here it is added to your code:

Expand|Select|Wrap|Line Numbers
  1. #!/opt/perl/bin/perl
  2. print "Content-type: text/html\n\n";
  3.  
  4. # The following accepts the data from the form and splits it into its component parts
  5.  
  6.  
  7.  
  8.         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  9.  
  10.         @pairs = split(/&/, $buffer);
  11.  
  12.         foreach $pair (@pairs)
  13.         {
  14.                 ($name, $value) = split(/=/, $pair);
  15.                 $value =~ tr/+/ /;
  16.                 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  17.                 $FORM{$name} = $value;
  18.         }
  19. print "<p>";
  20. print "<p>";
  21. print " u selecte rel: $FORM{Release}<p>";
  22. exit(0);
  23.  
Try again and see if that gets your above code working.

But you want to stop on this path you have taken. If you are serious about wanting to write perl based CGI scripts you should use the CGI module that comes with all standard distributions of perl.

http://perldoc.perl.org/CGI.html
Jul 22 '08 #2

P: 10
ya egxactly...header is missing thas why its giving
that error....
Sep 14 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.