>my $dbcon= DBI->connect("dbi:mysql:dbname=dbcontactos","root",""); >my $sql = $dbcon->prepare("select name,pass from Utilizador where name='?' >and pass='?'"); >$sql->execute($user,$pass); > if($sql == 1){ >redirect to other page > } > if($sql == 0){ >stay in the login page > }
Not quite sure what you are expecting $sql to be. If your intention is to compare $pass or other table variables to the value in column before proceeding why not just pull it into a structure that will allow you to do so? : my $pass; my $name; my %record; my $sql = "select name,pass from Utilizador where name='?' and pass='?'"; my $sth = $dbh->prepare($sql); $sth->execute($name,$pass); my $rowref; my $column; my $val; while ($rowref = $sth->fetchrow_hashref()) { #not sure if you will have multiple records so you may need to exit #the loop after %record is filled the first time while (($column, $val) = each %$rowref) { $record{$column} = $val; } } If ($record{'pass'} eq $pass) { #redirect to other page } else { #stay on logon } -M -----Original Message----- From: David Silva [mailto:david...@gmail.com] Sent: Wednesday, October 14, 2009 6:30 AM To: dbi-users@perl.org Subject: Stuck with form validation Hi everyone, I have a form with username and password, and when the user enter the right user and pass he/she go to other page. (that is my thought) What i did? my $dbcon= DBI->connect("dbi:mysql:dbname=dbcontactos","root",""); my $sql = $dbcon->prepare("select name,pass from Utilizador where name='?' and pass='?'"); $sql->execute($user,$pass); if($sql == 1){ redirect to other page } if($sql == 0){ stay in the login page } My problem is that i can't see any other way to do this and even if the values are correct with the ones in database it stays in the login page. How can i do this? Thank you -- David Silva