Hi David,
at first thanks for your reply.
I'll try to explain how my script is supposed to work:
-> sub Online_Database_Search
initial script, no user input needed
if f_name, f_surname are supplied and button is pressed, sub
get_pass is called
->sub get_pass
collects $pass from user (while doing this calls sub fetch)
($password2 = &fetch;)
->sub fetch
requires $f_name, $f_surname (and $action eq "pw")
fetches $password2 from mysql DB using $f_name, $f_surname
returns $password2 to main script
[if $pass eq $pasword2 sub pageone is called...]
I hope this explains it a little bit better...
Regards,
Sven
On Monday, May 6, 2002, at 12:04 AM, David Kirol wrote:
> Sven,
> I'm not sure what you are trying to do with the script in your post. I
> played with it (after reconstructing a partial table on a local MySql
> db)
> and noticed you never disconnected from the db. Passing password2 to the
> next script could be done as a hidden field or parameter. If you review
> your
> data flow (actually write it down) that might clarify it for you.
> Something
> like:
>
> Initial script:
> input required from previous script - none
> print welcome
> branch 1
> registration script
> ...
> branch 2
> login script
> collect first and last name
> verify names in db
> output to next script s2 parameters f_name, f_surname
> Script s2:
> input required from previous script - parameters f_name, f_surname
> print welcome
> collect password
> ...
> Doing this will fragment the task and allow you to focus on each part
> and
> allow you to do things like implement a consistent error handling
> routine
> across the application, centralize database access, etc.
> You may find it handy to use:
>
> use CGI::Carp qw( fatalsToBrowser );
>
> in your cgi scripts (it saves me alot of trips to the Apache error log)
> If you can explain the dataflow better (even cgi1 calls cgi2 to
> register or
> cgi3 to log a member in...) I might be able to help out more, but what I
> developed so far might not be of any use to you (because of my lack of
> understanding).
> David
>
>
> -----Original Message-----
> From: Sven Bentlage [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 05, 2002 3:05 AM
> To: [EMAIL PROTECTED]
> Subject: return values to sub
>
>
> Hi everyone!
> I started learning perl about one month ago.
> After havin fun and even getting some scripts running, the fun stopped 3
> days ago. :(
>
> Having found a problem I am not able to figure out myself, I'm not quite
> sure any more what to do.
> In my script (see below for excerpt) the user enters his/her
> name/surname. by using those the password is retrieved from am mysql DB
> via DBI, which is done in a subroutine (&fetch).
> It works correct, displays the $password2 as it should. But I could not
> yet figure out, how to pass the $password2 on to the next subroutine
> (&pageone), which is called from inside an if-construct.
> (If I do not use the if-construct, all is displayed on the same page at
> the same time....)
>
> Calling sub fetch from within the next subroutine again does not work
> either :(
>
> If anybody can help me, i would be very grateful since I do not know
> howw to solve that problem...
>
>
> Regards,
>
> John
>
>
> Here's the code
>
> #!/usr/bin/perl -w
>
> use CGI qw(param);
> use DBI;
> use strict;
>
> ###########################
> # Config section
> ###########################
>
> # action
> my $action = param('action');
>
> #data source name
> my $dsn = 'DBI:mysql:etpa:localhost:3306';
>
> #user
> my $db_user = 'etpup';
>
> #pass
> my $db_pass = '1234abcd';
>
>
> #f_name
> my $f_name = param('f_name');
>
> #f_surname
> my $f_surname = param('f_surname');
>
> #pass
> my $pass = param('password');
>
> #etp
> my $f_etp = param('f_etp');
>
>
>
> unless ($action){&Online_Database_Search}
> elsif (($action eq "pw") and (($f_name eq "") or ($f_surname eq
> ""))){&Online_Database_Search}
>
> my $password2 = &fetch;
> &pw;
>
>
> if ($action eq "login"){&pageone}
> elsif ($action eq "name"){&search_by_name}
> elsif ($action eq "print_name"){&print_name}
> elsif ($action eq "etp"){&search_by_etp}
> elsif ($action eq "print_etp"){&print_etp}
> elsif ($action eq "nation"){&search_by_nation}
> elsif ($action eq "print_nation"){&print_nation}
> elsif ($action eq "keyword"){&search_by_keyword}
> elsif ($action eq "print_keyword"){&print_keyword}
> #########################################################################
> # subs
> #########################################################################
>
> sub pw {
>
>
>
>
> my $dbh = DBI->connect( $dsn, $db_user, $db_pass ) || die "Can
> nat
> connect to MySQL DB $DBI::errstr\n";
>
> my $get_pw = $dbh->prepare(
> "select name, surname, password from memberscopy
> where name = '$f_name' and surname = '$f_surname' "
> );
>
> $get_pw->execute();
>
> while ( my ( @data ) = $get_pw->fetchrow_array() ) {
>
> print "Content-type: text/html\n\n";
>
> print qq~
> <html>
> <head>
> <title>Enter password</title>
> </head>
> <body bgcolor="#000850" text="#FFFFFF" link="FFFF00"
> target="main">
> $password2
> <div align="center">
> <font face="Arial, Helvetica, sans-serif" COLOR="#FFFFFF">
> <b>Dear $data[0] $data[1],</b><br><br>
> <div align="left">Please enter now the password you have
> received by email.<p>
> If you did not receive an email within 15 minutes after
> applying for a password, <p>
> please send an <a href="mailto:XXX\@xxx.xx">email to the
> Administrator.</a>
> </div>
> </font>
> <br>
>
> <form action="login2.cgi" method="post" target="main">
> <input type="hidden" name="action" value="login">
>
> <font face="Arial, Helvetica" size="2">Passwort</font>
> <input type="password" name="password" size="15"><br><br>
>
> <input type="Submit" value="Log In">
> </form>
> </div>
>
> $data[0], $data[1]
> </body>
> </html>
> ~;
>
> }
>
> }
>
> #########################################################################
>
> sub fetch {
>
>
> my $dbh = DBI->connect( $dsn, $db_user, $db_pass) ;
>
> ( my $password2 ) = $dbh->selectrow_array( "
> select password from memberscopy
> where name = '$f_name'
> and surname = '$f_surname' "
>
> );
>
> return $password2;
>
> }
>
>
> #########################################################################
>
> sub pageone {
>
>
>
>
> print "Content-type: text/html\n\n";
>
> print qq~
> <html>
> <head>
> <title> Welcome</title>
> </head>
> <body bgcolor="#000850" text="#FFFFFF" link="FFFF00">
> // $password2
> <div align="center">
> <font face="Verdana, Arial" size="2" color="#FFFFFF">
> <b>ETPA member Area - Welcome ( / $password2)</b></font><br><br>
> In this area...[blablablablabla]<br>
> <image src="../pics/etp-logo_cr-mini.gif" align="center">
> PASSWORT "$password2"
> <hr>
> </body>
> </html>
> ~;
>
>
>
>
> }
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]