1

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);
12
  • 3
    "actually displays an error" — What error?! Commented Dec 1, 2014 at 21:04
  • 3
    Danger: You aren't hashing your passwords and need to take better care of your users' passwords. Commented Dec 1, 2014 at 21:06
  • 2
    Using a CSV file as a database is a terrible idea. If you aren't going to use a real RDBMS then at least use something like SQLite. (And if you are going to use a CSV file, then use a CSV library that will properly escape input) Commented Dec 1, 2014 at 21:06
  • 2
    CGI is inefficient at best, and CGI.pm is going to be removed from the next release of Perl. Use PSGI and Plack instead. If you really want to use CGI then Plack has a CGI handler. Commented Dec 1, 2014 at 21:09
  • 1
    Using Plack doesn't preclude using CGI - I pointed to the CGI handler for it. CSV is still a terrible idea, but you really should use a library for it rather then just printing with commas. Try executing the script (on the command line) with ./foo.cgi instead of perl foo.cgi. Commented Dec 1, 2014 at 21:13

1 Answer 1

1

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'.

Sign up to request clarification or add additional context in comments.

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.