0

我有以下代码:

<?php
if(!empty($_POST)){
    $db = new mysqli('localhost', 'root', '', 'verif1');
    $password = $_POST['pass'];
    $username = $_POST['user'];
        $table = "admins";
    $password = hash("sha256", $password);
    $statement = $db->prepare("SELECT COUNT(*) FROM {$table} WHERE username = ? AND password = ?");
    $statement->bind_param("ss", $username, $password);
    $statement->execute();
    $statement->bind_result($numrows);
    if($numrows == 1){
        echo "yeah correct!<br>";
    }else{
        echo "No :(<br>";
    }
}


?>

<form action="" method="POST">
    <input type="textbox" name="user">
    <br>
    <input type="password" name="pass">
        <br>
    <input type="submit">
</form>

我确信一切都是正确的(没有错误抛出,什么都没有)它只是不起作用!我尝试 print_r() 来查看已返回的反对,我得到了这个:在 execute() 之后我这样做:

print_r($statement);
die();

它给了我这个:

mysqli_stmt 对象 ( [affected_rows] => -1 [insert_id] => 0 [num_rows] => 0 [param_count] => 2 [field_count] => 1 [errno] => 0 [error] => [error_list] =>数组 () [sqlstate] => 00000 [id] => 1)

4

2 回答 2

0

如果您查看文档 - http://www.php.net/manual/en/mysqli-stmt.bind-result.php您会发现您忘记了fetch()数据

$statement->fetch();
于 2013-07-24T04:53:11.653 回答
-1

您可以使用以下代码来计算行数而不是$statement->bind_result($numrows);

$statement->store_result();
if ($statement->num_rows == 1)
    echo "yeah correct!<br>";
} else {
    echo "No :(<br>";
}
于 2013-07-24T04:59:53.847 回答