0

I'm, trying to run a perl script from html, but I'm getting error during execution. Here is my html and 2 lines perl code. The error code is not very descriptive just says "Internal Server Error" and some other lines. I also want to know how to display the receive user name in the perl script.

pwd
/var/www/cgi-bin

ls -l
total 4
-rwxr-xr-x 1 root root 49 Aug 26 16:49 username.pl

Html Code:

<html>
<head>
</head>
<body>
<h1> Hello </h1>
<form action="/cgi-bin/username.pl" method="POST">
     <input type="text" name="username">
     <input type="submit">
</form>
</body>
</html>

Perl code:

#!/usr/bin/perl
print "Received user name is\n";
2

2 Answers 2

2

Your Perl script is not generating appropriate CGI headers. Please read perldoc CGI, or, for a quick answer:

#!/usr/bin/perl
use strict;
use CGI;

my $q = CGI->new();
my $username = $q->param("username");
print $q->header(-type => "text/plain");
print "Received username is $username\n";
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Could you also explain just a little bit lines wit "my" in them?
Read the documentation I linked to.
1

1>.my declares the listed variables to be local to the enclosing block, file.

2>.if you have a text box name user in your html page

i.e. something like this:-

<td><b><font color="green" size="3">USER</font><input type="text" name="user" value="">

then try this

my $user=$query->param("user");

in your cgi script and get the input in the variable $user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.