使用MYSQLi检查数据库中是否存在用户名/激活了用户名
问题描述:
$username = mysqli_real_escape_string($_POST['username']);
$result = mysqli_query($connect, "SELECT * FROM account WHERE username='".$username."' AND activate='0'");
while($row = mysqli_fetch_assoc($result)) {
echo 'Account not activated.';
}
我是MYSQLi的新手,如果用户输入错误的用户名并且未激活用户名,我需要如何显示错误的帮助.到目前为止,我已经收到了上面的代码.
I'm new to MYSQLi and I need help on how do I show an error if the user enter a wrong username and its not activated. So far I got the code above.
答
尝试一下
$username = mysqli_real_escape_string($_POST['username']);
$result = mysqli_query($connect, "SELECT * FROM account WHERE username='".$username."' AND activate='0'");
if ($result->num_rows) {
echo "you are activated !!";
}
else
{
// do what u like here if not activated
}