in reply to Re^6: Redirecting values from 1 script to another
in thread Redirecting values from 1 script to another
Your code should look like this -- notice how it begins with the logic that checks the parameters:
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.#!/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...
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... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Redirecting values from 1 script to another
by Nik (Initiate) on Apr 17, 2006 at 09:52 UTC |