in reply to Re^5: Redirecting values from 1 script to another
in thread Redirecting values from 1 script to another

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^7: Redirecting values from 1 script to another
by chromatic (Archbishop) on Apr 16, 2006 at 16:47 UTC
    Please explain to me what you mean!

    What part of "Move the code that checks if a username already exists and adds a user to the database and redirects to come before you print the header" is difficult to understand? Now obviously you'll also have to move the part of the code that assigns query parameters to variables too, but all that you have to do is move two pieces of code. That's it.

    It would be much, much easier to help you if you were clear on what you do not understand rather than saying "I can't do that".

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^7: Redirecting values from 1 script to another
by graff (Chancellor) on Apr 17, 2006 at 02:07 UTC
    Okay, let's see if we can apply the advice in the various replies, and then maybe (finally) you will understand what everyone else is talking about.

    Your code should look like this -- notice how it begins with the logic that checks the parameters:

    #!/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... }
      Tahnk you tis pretty clear now although i understood what i wasnt thinking correctly 5 minutes before when seeing fishbot's post where i am expalining why i got stuck.

      Anyway yesterday, i decided that i woudl enver understand this so i renamed login pl to register.pl and use it only to register people. For login i redirect userscoming from index.pl to an admin script where it is http access authenticated and if the user sign correctly then admin.pl is runnign and redirecting to show.pl which i do database stuff
      Apache's authentication has a fancy pretty coll dialog box in xp way more advanced than the not so good looking form table that i ahve created :-). I just having a slighlty different problem that iam asking in a later thread of mine

      Thank you very much guys for your patience with me.
      Actually i ahve re-read all thread and things are crystal clear.

      To say it better my problem was that i was thinking that the code must follow the logic of order of how things must be printed on screen but i know reilized that it doesent have to work this way.
      I mean just because the cleitn must see the table first and then gives data doesnt mena that the code should print him the table first and then try to redirect. It can instead check if data was already being submitted and then if not then pritn the user form to fill. Its vice versa actaully ;-) This would help me a lot of later disign models.