-2

我无法弄清楚这几行有什么问题:

    if  ( $stmt = $db->prepare('SELECT * FROM users WHERE username = ? LIMIT 1');
    $stmt->bind_param('s', $username);
    $stmt->execute();
    $stmt->store_result();
    $stmt->fetch();
    $stmt->num_rows == 1;
    )           

    {
    $errors[] = "Username is taken.";
    }
4

2 回答 2

0

不知道你是如何得到你的其他代码的,但我认为你想要这样的东西:

$stmt = $db->prepare('SELECT * FROM users WHERE username = ? LIMIT 1');
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->bind_result($res);

if($stmt->num_rows == 1)
{
    $errors[] = "Username is taken.";
}

您的原始代码中也有不必要的提取

于 2013-08-28T21:09:59.457 回答
0
if($stmt = $db->prepare('SELECT * FROM users WHERE username = ? LIMIT 1'))
{
    $stmt->bind_param('s', $username);
    $stmt->execute();
    $stmt->store_result();
    if($stmt->num_rows > 0)
    {
        $errors[] = "Username $username is taken.";
    }
    $stmt->free_result();
    $stmt->close();
}
于 2013-08-28T21:27:24.447 回答