使用PDO从数据库访问返回的数据

时间:2018-03-22 16:33:05

标签: php pdo sqlite

我正在尝试从两个列访问,一个来自Count(userid),另一个来自rank。此代码确实返回计数但不返回 秩。

<?php

$myusername = strtolower($_POST['username']);
$mypassword = md5($_POST['password']);
$sql = "SELECT COUNT(userid), rank FROM users_ WHERE "
        . "username = ? AND password = ?";   // note the "?" placeholders
$stmt = $dbh->prepare($sql);
$stmt->execute([$myusername, $mypassword]);

$row = $stmt->fetch();
//echo $row[0]; // this displays the returned count.
echo $row[1];
if ($row[0] == 1) {
    header("location: dashboard.php");
} else {
    $error = "Invalid username or password.";
}

0 个答案:

没有答案