使用MYSQLi检查数据库中是否存在/激活用户名

时间:2013-03-17 14:19:01

标签: php mysql database mysqli username

$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的新手,如果用户输入错误的用户名并且未激活,我需要帮助我如何显示错误。到目前为止,我得到了上面的代码。

1 个答案:

答案 0 :(得分:1)

试试这个

  $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
    }