日期:2014-05-17 浏览次数:20444 次
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>"; } }
$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);