jch02140
11-13-2005, 02:44 AM
Hi,
I am new to CGi and trying to code a registration page in CGI. However, I run into some trouble and the code won't work... I am not sure what wrong though...
#!/usr/local/bin/perl -w
use strict;
use CGI::Pretty;
#use CGI qw(:standard);
require "useful_functions.lib";
my $q=new CGI::Pretty;
my $aLine;
my $registered_level = 0;
my $username = $q->param("username"); # Get demand username
my $password = $q->param("password");
my $level_of_sub = $q->param("level_of_sub");
my $registed=0;
my $name = $q->param("name");
my $email = $q->param("email");
header("Register CGI!!!");
saveTo("password.txt");
new_portfolio();
footer();
sub saveTo{
my $file = shift@_;
my $aLine;
my $bool=1;
if (-e $file) {
open (FILE, "$file") or errorMsg("Cannot load the password.txt file. Check the permission");
while ($aLine=<FILE>) {
my @temp_container=split(/\|/, $aLine);
if ($username eq shift(@temp_container)) {
print "<h2>The username $username is taken. Please make another choice!</h2>";
print "<h2>Click <a href=index.html>HOME PAGE</a> to return.</h2>";
print "<h2>Or click <a href=register.html>sign-up</a> to try again.</h2>";
$bool=0;
$registed=0;
}
}
close(FILE);
if ($bool==1){
open(SAVE, ">>$file") or errorMsg("<h3>The password.txt does not exist</h3>");
print SAVE "$username\|$password\|$name\|$level_of_sub\|$email\n";
close(SAVE);
print"<h2>Register Done!!!</h2><br/><big>Click <a href='home.html'>here </a> to return home.</big>";
}
}
}
sub new_portfolio{
if ($registed=1){
open(PORTFOLIO, ">$username.info") || errorMsg("<h2>File not created! Please verify the permison.</h2>");
print PORTFOLIO "Subscription Level\|$level_of_sub\n";
close(PORTFOLIO);
}
}
I am new to CGi and trying to code a registration page in CGI. However, I run into some trouble and the code won't work... I am not sure what wrong though...
#!/usr/local/bin/perl -w
use strict;
use CGI::Pretty;
#use CGI qw(:standard);
require "useful_functions.lib";
my $q=new CGI::Pretty;
my $aLine;
my $registered_level = 0;
my $username = $q->param("username"); # Get demand username
my $password = $q->param("password");
my $level_of_sub = $q->param("level_of_sub");
my $registed=0;
my $name = $q->param("name");
my $email = $q->param("email");
header("Register CGI!!!");
saveTo("password.txt");
new_portfolio();
footer();
sub saveTo{
my $file = shift@_;
my $aLine;
my $bool=1;
if (-e $file) {
open (FILE, "$file") or errorMsg("Cannot load the password.txt file. Check the permission");
while ($aLine=<FILE>) {
my @temp_container=split(/\|/, $aLine);
if ($username eq shift(@temp_container)) {
print "<h2>The username $username is taken. Please make another choice!</h2>";
print "<h2>Click <a href=index.html>HOME PAGE</a> to return.</h2>";
print "<h2>Or click <a href=register.html>sign-up</a> to try again.</h2>";
$bool=0;
$registed=0;
}
}
close(FILE);
if ($bool==1){
open(SAVE, ">>$file") or errorMsg("<h3>The password.txt does not exist</h3>");
print SAVE "$username\|$password\|$name\|$level_of_sub\|$email\n";
close(SAVE);
print"<h2>Register Done!!!</h2><br/><big>Click <a href='home.html'>here </a> to return home.</big>";
}
}
}
sub new_portfolio{
if ($registed=1){
open(PORTFOLIO, ">$username.info") || errorMsg("<h2>File not created! Please verify the permison.</h2>");
print PORTFOLIO "Subscription Level\|$level_of_sub\n";
close(PORTFOLIO);
}
}