#!/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', {RaiseError=>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( 'Εγγραφή' )) { # user 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 invalid, or # -- user hit the "new user" submit button, but params were incomplete or # username was already in use print header(...); print start_html(...); if ( @param_errors ) { # show error message(s) } # print the form...