Home > Backend Development > PHP Tutorial > 关于pdo的一个疑问,该如何解决

关于pdo的一个疑问,该如何解决

WBOY
Release: 2016-06-13 10:17:28
Original
777 people have browsed it

关于pdo的一个疑问

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->if (isset($_POST['loginName']) && isset($_POST['pwd']) && $_POST['action'] ==    'submit') {    $loginName = $_POST['loginName'];    $pwd = $_POST['pwd'];        echo $loginName.' '.$pwd;    $sql = "SELECT COUNT(*) FROM tb_esq WHERE login_name = :loginName AND pwd = :pwd";    require_once ('conn.php');    $sth = $db->prepare($sql);    $sth->bindParam(':loginName', $loginName, PDO::PARAM_STR, 25);    $sth->bindParam(':pwd', $pwd, PDO::PARAM_STR, 25);    $sth->execute();    $rowCount = $sth->fetchColumn();    var_dump($rowCount);//一直是0    $db = NULL;    if ($rowCount == 1) {        echo "<script>window.location=\"index.html\";</script>";    } else {        alert('用户名或密码错误!');        echo "<script>window.location=\"login.php\";</script>";    }}
Copy after login


在提交了数据库中存在的用户名和密码之后还是提示密码错误,为什么呢

------解决方案--------------------
先用普通查询 看能否得到数据
PHP code
$sql = "SELECT COUNT(*) FROM tb_esq WHERE login_name = '$loginName' AND pwd = '$pwd'";$result = $db->query($sql);$row = $result->fetch(PDO::FETCH_ASSOC);print_r($row);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template