我无法弄清楚这几行有什么问题:
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.";
}
答案 0 :(得分: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.";
}
原始代码中有不必要的提取,也是
答案 1 :(得分: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();
}