Monday, 9 September 2013

strict with CGI::AJAX

strict with CGI::AJAX

I have set of code for updating a password in the table, here I'm using
CGI::AJAX module to update the password and get the popup screen on
corresponding execution.When using that code with my application it is
executing properly but I didn't get the output(means Perl subroutine is
not called when JavaScript function to get use.password is not updated
into table). I don't get any error either.
#!/usr/bin/perl -w
use strict;
use CGI;
use DBI;
use Data::Dumper;
my $p = new CGI qw(header start_html end_html h1 script link);
use Class::Accessor;
use CGI::Ajax;
my $create_newuser;
my $ajax = new CGI::Ajax('fetch_javaScript' => $create_newuser);
print $ajax->build_html($p,\&Show_html,{-charset=>'UTF-8', -expires=>'-1d'});
sub Show_html
{
my $html = <<EOHTML;
<html>
<body bgcolor="#D2B9D3">
<IMG src="karvy.jpg" ALT="image">
<form name='myForm'>
<center><table><tr><td>
<div style="width:400px;height:250px;border:3px solid black;">
<center><h4>Create New Password's</h4>
<p>&nbsp User Name</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<INPUT
TYPE="text" NAME="user" id = "user" size = "15" maxlength = "15" tabindex
= "1"/></p>
<p>&nbsp Password:</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<INPUT
TYPE=PASSWORD NAME="newpassword" id = "newpassword" size = "15" maxlength
= "15" tabindex = "1"/></p>
<p>&nbsp Re-Password:</b>&nbsp&nbsp&nbsp<INPUT TYPE=PASSWORD
NAME="repassword" id = "repassword" size = "15" maxlength = "15" tabindex
= "1"/></p>
<input type="submit" id="val" value="Submit" align="middle" method="GET"
onclick="fetch_javaScript(['user','newpassword','repassword']);"/><INPUT
TYPE="reset" name = "Reset" value = "Reset"/>
<p>Main Menu <A HREF = login.pl>click here</A>
</center>
</div>
</td></tr></table></center>
</form>
</body>
</html>
EOHTML
return $html;
}
$create_newuser =sub
{
my @input = $p->params('args');
my $user=$input[0];
my $password=$input[1];
my $repassword=$input[2];
my $DSN = q/dbi:ODBC:SQLSERVER/;
my $uid = q/123/;
my $pwd = q/123/;
my $DRIVER = "Freetds";
my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't
Connect SQL";
if ($user ne '')
{
if($password eq $repassword)
{
my $sth=$dbh->do("insert into
rpt_account_information
(user_id,username,password,user_status,is_admin)
values(2,'".$user."','".$password."',1,1)");
my $value=$sth;
print $value,"\n";
if($value == 1)
{
print 'Your pass has benn
changed.<a
href="login.pl">Return</a>
to the main page';
}
}
else
{
print "<script>alert('Password and
Re-Password does not
match')</script>";
}
}
else
{
print "<script>alert('Please Enter the
User Name')</script>";
}
}

No comments:

Post a Comment