A very easy mysql problem

A very easy mysql problem

am 02.10.2003 09:31:20 von uth

I want to compare the password, which the user typed in (in a textfield) =
with a password, which is in a MySQL-db.

I tried the following:


=09my $dbh =3D db_open("mypoll300903", "testuser", "authmysql");
=09my $sth =3D $dbh->prepare("select password from table1 where prename =3D=
=20\"testprename\" and name =3D \"testname\";")
=09 or die ($dbh->errstr);
=09$sth->execute or die $sth->errstr;
=09print "$sth";=09
=09$dbh->disconnect();=20

$sth is not yet what I want. It is something like the structure of what I=
=20need.

=09I'd like to do the following:

=09if ($passdb es $passusr) { ## $passdb =3D the transformed $sth=20
=09 $OK =3D 1;
=09}



Any help will be greatly appreciated,

Thomas



Content Security by MailMarshal

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=3Dgcdmp-msql-mysql-modules @m.gmane.org

Re: A very easy mysql problem

am 03.10.2003 09:40:12 von Aleksey Kishkin

Unternährer Thomas wrote:
>
> I want to compare the password, which the user typed in (in a textfield)
> with a password, which is in a MySQL-db.
>
> I tried the following:
>
>
> my $dbh = db_open("mypoll300903", "testuser", "authmysql");
> my $sth = $dbh->prepare("select password from table1 where prename =
> \"testprename\" and name = \"testname\";")
> or die ($dbh->errstr);
> $sth->execute or die $sth->errstr;
> print "$sth";
> $dbh->disconnect();
>
> $sth is not yet what I want. It is something like the structure of what I need.
>

After execution you must retrieve result records. Common way is:
my @record;
while ( @record = $sth->fetchrow_array() )
{
# here we have a result record in @record
}

But as far as you expect only one record with only one field, you can perform
it this way:

my $dbh = db_open("mypoll300903", "testuser", "authmysql");
my $sth = $dbh->prepare("select password from table1 where
prename = \"testprename\" and name = \"testname\";")
or die ($dbh->errstr);
$sth->execute or die $sth->errstr;
my $userpassword = $sth->fetchrow_array(); # in scalar context
# fetchrow_array returns
# first field
if ( defined($userpassword) )
{
# compare password as you wanted
} else {
print "Nobody found";
}

$dbh->disconnect();



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: A very easy mysql problem

am 03.10.2003 09:40:12 von Aleksey Kishkin

Unternährer Thomas wrote:
>
> I want to compare the password, which the user typed in (in a textfield)
> with a password, which is in a MySQL-db.
>
> I tried the following:
>
>
> my $dbh = db_open("mypoll300903", "testuser", "authmysql");
> my $sth = $dbh->prepare("select password from table1 where prename =
> \"testprename\" and name = \"testname\";")
> or die ($dbh->errstr);
> $sth->execute or die $sth->errstr;
> print "$sth";
> $dbh->disconnect();
>
> $sth is not yet what I want. It is something like the structure of what I need.
>

After execution you must retrieve result records. Common way is:
my @record;
while ( @record = $sth->fetchrow_array() )
{
# here we have a result record in @record
}

But as far as you expect only one record with only one field, you can perform
it this way:

my $dbh = db_open("mypoll300903", "testuser", "authmysql");
my $sth = $dbh->prepare("select password from table1 where
prename = \"testprename\" and name = \"testname\";")
or die ($dbh->errstr);
$sth->execute or die $sth->errstr;
my $userpassword = $sth->fetchrow_array(); # in scalar context
# fetchrow_array returns
# first field
if ( defined($userpassword) )
{
# compare password as you wanted
} else {
print "Nobody found";
}

$dbh->disconnect();



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org