Maya
Maya

Reputation: 11

Perl HTML CGI web page error

This is my perl code for a registration web page. It should append values to a csv page. It compiles perfectly but when I conncet it to my HTML program the web pae actually displays an error. This is the page http://cs.mcgill.ca/~zviran1/register.html HELP

#!/usr/loca/bin/perl
use CGI;
my $q = CGI->new();
use strict;

my $username = $q->param('username');
my $name = $q->param('name');
my $password = $q->param('password');
my @array = ($name, $username, $password, "\r");
my $line = join(' , ', @array);

print "Content-type: text/html \n\n";
my $file = 'Members.csv';
open (FILE, '+>>$file') or die "Cannot open file";
my $inputLine = <FILE>;
while($inputLine = <FILE>)
{
if(index($line, $username) != 4){
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE> Error Page </TITLE> \n";
print "</HEAD>\n";
print "<BODY>\n";
print "The username you have entered is already in use.";
print "<br><a href=\"index.html\">Home Page</a> \n";
print "<br><a href=\"register.html\">Registration Page</a> \n";
print "</BODY>\n";
close(FILE);
}
else {
#seeking to the end of the file to append
seek(FILE, 0, 2);
print FILE $line;
}
}
close(FILE);

Upvotes: 1

Views: 82

Answers (1)

EpisodeIV
EpisodeIV

Reputation: 11

Are you sure your Perl interpreter is where you want it to be? Your shebang line is

#!/usr/loca/bin/perl

which is probably missing an 'l'. When you run the script locally via perl myscript.pl it ignores that line but when you run it under a webserver like Apache, it's actually used to find the Perl interpreter.

Other than that, have a look at your web server log (you should be able to access the error log even on simple hosting providers) because the error page your browser gets is merely the web server saying 'Hey, something went wrong there'.

Upvotes: 1

Related Questions