#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBD::mysql;
use POSIX qw(strftime);
my @param_errors = ();
my $dbh = DBI->connect('DBI:mysql:nikos_db', 'root', 'password', {Rais
+eError=>1});
if ( param( 'Σύνδεση' )) { # user
+hit the "login" button
# check that username, password and email are filled in,
# query database to see if these values are okay ...
# if login is okay, redirect and exit
# otherwise, push an error message onto @param_errors
}
elsif ( param( 'Εγγραφή' )) { # us
+er hit "new user" button
# check whether all necessary params are present,
# query database to see if user-supplied username has been used ..
+.
# if okay, insert new user record into database, redirect and exit
# otherwise, push error message(s) onto @param_errors
}
# get here if there was no redirection -- that is, just one of
# the following is true for this run of the script:
# -- user came directly to the login page (no params were set), or
# -- user hit the "login" submit button, but login fields were invali
+d, or
# -- user hit the "new user" submit button, but params were incomplet
+e or
# username was already in use
print header(...);
print start_html(...);
if ( @param_errors ) {
# show error message(s)
}
# print the form...
Now, when you redirect to some other cgi script that you have written, you can include the parameters in the url that the are known from the login process and that will be needed by the other script.
BTW, I think you have the wrong sort of logic for confirming whether the login parameters are okay. You should query the database like this:
my $select = $dbh->prepare("select email,password from users where u
+sername=?");
$select->execute( $username );
my @row = $select->fetchrow_array;
if ( @row != 2 or $email ne $row[0] or $password ne $dbpassword ) {
push @error_mesgs, "bad login...";
} else {
#login was okay, so redirect...
}
|