pdo select语句不能正常工作

时间:2014-03-28 02:21:16

标签: php mysql sql pdo

我已经厌倦了试图找到错误,解决方案,但我没有得到任何方式, 代码对我来说似乎没问题。

我在下面有一个登录系统的pdo声明,我输入了正确的电子邮件和密码,但总是在此处输入其他条件

      else //always entering here  
            {                   
              echo '<pre>';     //I was trying to see whats happening with printf
              print_r($result); //but this print_r is not showing nothing 
              echo '</pre>';

              echo ' Wrong Password';  //I always get this message   
            }

我的pdo声明:

if(isset($_POST['sendLogin']))
{
  $f['email'] = $_POST['email'];
  $f['pass'] =  $_POST['pass'];

  $autEmail = $f['email'];
  $autpass = $f['pass'];
  $searchEmail = $pdo->prepare("SELECT * FROM users where email = :email");  
  $searchEmail->bindValue(":email", $autEmail);  
  $searchEmail->execute();
  $rows = $searchEmail->fetchAll();
  $num_rows = count($rows);
  $result = $searchEmail->fetch(PDO::FETCH_ASSOC);

  if($num_rows == 1)
   {

     if($autEmail == $result['email'] && $autpass == $result['pass'])
    {
           $_SESSION['result'] = $result;
           header('Location:'.$_SERVER['PHP_SELF']);
        }

   else //always entering here 
    {                   
        echo '<pre>';
        print_r($result);
        echo '</pre>';
        echo ' Wrong Password';     
    }
  }
}

1 个答案:

答案 0 :(得分:1)

您正在计算错误的行数。使用$num_rows = $searchEmail->rowCount();计算行数。