Çäðàâñòâóéòå peace,

Thursday, July 07, 2005, 6:08:06 AM, Âû íàïèñàëè:

putt> =============

putt> Dear Per GUru;
putt> I have problem with this code, which I can't run as what I expected, as 
putt> I coded the register form, it run fine with the connection with MYsql
putt> database, and apache web server, however this one since nothing
putt> problem with mysql connection, it must something error inside the code
putt> itself. Thank very much for your help

putt> The program do the following 
putt> -Print form
putt>   1- User input login name
putt>   2- User input secret question
putt>   3- User input secret answer

putt> -check from the database
putt> -all the information have to validate with information store in the 
database
putt> -if all the information provited by the users all the same as in the 
database, 
putt> -new form for new password is display
putt>   1- User input for the new passwords for two times
putt> -if validate the password (2 are matched), they will allow to record
putt> it to the database.
putt> -the program eliminate.

putt> Thank very much for your help, 

putt> ===========================
putt> #!/perl/bin/perl

putt> use strict;
putt> use warnings;
putt> use CGI qw(:standard);
putt> use DBI;



my $dth= DBI->>connect( "dbi:mysql:wexam:localhost", "root","lyekuan")
putt> or & dienice("Can't nonnect to db: $DBI::errstr");

putt> print header(),start_html(-title=>'Forget Password'),br(),br(),br();




putt> my $login_name=param('login_name');
putt> my $secret_answer=param('secret_answer');
putt> my $secret_question=param('secret_question');

putt> my $message;

putt> my @input_merg=(qw/$login_name $secret_question $secret_answer/);

putt> if(param('submitPassword'))
putt> {
putt>        my $check_input = &validate_retrieve($dth,[EMAIL PROTECTED]);

    In line above You declare scalar variable $check_input and in line
    below You try call sub reference to which $check_input contains.
    But $check_input is scalar, not ref because validate_retrieve() sub
    returns only scalars.

putt>        if(&$check_input eq '1')

   In line above You maybe should replase "&$check_input" with
   "$check_input". More, your validate_retrieve() sub returns the
   number on success while "eq" operates on strings. Therefore You
   should or use "==" instead of "eq" in line above or (and it's
   better) return from validate_retrieve() sub string, not a number
   (e.g. "return '1'" instead of "return 1").
   
putt>        {
putt>                &new_password_form;
putt>                my $pass1=param('new_password1');
putt>                my $pass2=param('new_password2');
putt>                if($pass1 ne $pass2)
putt>                {
putt>                        &new_password_form;
putt>                }

putt>                if($pass1 eq $pass2){
putt>                record_password($dth,$pass1,$login_name);
putt>                $message="You have retrieved you password and have
putt> setted for the new one successfully";
putt>                &print_success($message);
putt>                }
putt>        }
putt>        else
putt>        {
putt>                print "<UL><font color=\"red\">&$check_input</font></UL>";
putt>                &print_form;
putt>        }
putt> }
putt> else
putt> {
putt>        &print_form;
putt> }

putt> print end_html();

putt> sub validate_retrieve
putt> {
putt>        my $dth=shift(@_);
putt>        my $data_to=shift(@_);

putt>        my $query_string=("SELECT loginame, secretquestion,
putt> secretanswer FROM WUSERS ");

putt>        my $sth=$dth->prepare($query_string);

putt>        $sth->execute() or &dbdie;

putt>        my $error_message;

putt>        my $retrieve=$sth->fetchrow_hashref;
putt>        $sth->finish();

putt>        if($retrieve->{loginame} ne @{$data_to}[0]){
putt>                $error_message .= '<LI> You may incorrectly type in the
putt> Login Name, please verify it!</LI>';
putt>        }

putt>        if($retrieve->{secretquestion} ne @{$data_to}[1]){
putt>                $error_message .= 'LI> Please verify your secret
putt> question, make sure it is entered correctly!</LI>';
putt>        }

putt>        if($retrieve->{secretanswer} ne @{$data_to}[2]){
putt>                $error_message .= 'LI> Please verify your secret
putt> answer, make sure it is entered correctly! </LI>';

putt>        }

putt>        if($error_message eq "")
putt>        {
putt>                return 1;
putt>        }
putt>        else
putt>        {
putt>                return ($error_message);
putt>        }

putt> }

putt> sub new_password_form
putt> {

putt>        print "<FORM METHOD='post'>\n<BR>";
putt>        print "<INPUT TYPE=\"hidden\" NAME=\"login_name\"
putt> VALUE=\"$login_name\">\n<BR>";
putt>        print "<DIV ALGIN=\"CENTER\">\n<BR>";
putt>        print qw(New Password: <INPUT TYPE='password'
putt> NAME='new_password1' size=20 maxlength=25><br>
putt>                     re-enter: <INPUT TYPE='password'
putt> NAME='new_password2' size=20 maxlength=25><br>
putt>                 );
putt>        print "<INPUT TYPE='submit'>\n<br>";
putt>        print "</FORM>";
putt>        print "</DIV>";

putt> }

putt> sub record_password
putt> {
putt>        my $dth=shift;
putt>        my $new_pass=shift;
putt>        my $login_name=shift;

      
putt>        my $update_query="UPDATE Wusers set password='$new_pass' WHERE
putt> loginame='$login_name' ";
putt>        my $sth=$dth->do($update_query);
putt>        $sth->finish;
putt> }

putt> sub dienice{
putt>        my ($msg)= @_;
putt>        print header;
putt>        print start_html("ERROR");
putt>        print "<h2>Error </h2>\n";
putt>        print $msg;
putt>        exit;
putt> }

putt> sub dbdie
putt> {
putt>        my ($package, $filename, $line) = caller;
putt>                my ($errmsg) = "Database error: $DBI::errstr<br>\n
putt> Called from $package $filename line $line";
putt>        &dienice($errmsg);
putt> }

putt> sub print_success
putt> {
putt>        my $msg=shift;
putt>        print "<h2> Forget password successfully retrieve</h2><br>";
putt>        print $msg;
putt>        exit;
putt> }

putt> sub print_form
putt> {
putt>        print <<Eof
putt>        <DIV ALIGN=center VALIGN=center>
putt>                <FORM METHOD=post>
putt>                <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=500
putt> HEIGHT=190 BGCOLOR="#895555">
putt>                  <INPUT TYPE=\"hidden\" NAME=\"submitPassword\"><BR>

putt>                <TH COLSPAN=2> <h2> Retrieve Password</h2>
putt>                </TH>

putt>                <TR>
putt>                        <TD ALIGN=right><b>Login Name:</b> </TD>
putt>                        <TD><INPUT TYPE=\"text\" NAME=\"login_name\"
putt> Size=20 MaxLength=20></TD>

putt>                </TR>

putt>                <TR>
putt>                        <TD ALIGN=right><b>Secret Question:</b></TD>
putt>                        <TD><INPUT TYPE=\"text\"
putt> NAME=\"secret_question\" size=40 MAXLENGTH=50></TD>
putt>                </TR>

putt>                <TR>
putt>                        <TD ALIGN=right><b>Secret Answer:</b></TD>
putt>                        <TD> <INPUT TYPE=\"text\"
putt> NAME=\"secret_answer\" size=40 MAXLENGTH=50><BR></TD>
putt>                </TR>
putt>                <TR>
putt>                <TD COLSPAN=2><hr noshade size=2 width=400 
ALGIN=center></TD>
putt>                </TR>

putt>                <TR>
putt>                <TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=submit
putt> value="Get Password"></TD>
putt>                </TR>
putt>                </TABLE>
putt>                </FORM>

putt>        </DIV>
putt> Eof
putt> }






-- 
Ñ óâàæåíèåì,
 Ñåðãåé                            mailto:[EMAIL PROTECTED]


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to