Check if username exist/activated in database using MYSQLi [duplicate]

走远了吗. 提交于 2020-04-18 06:00:06

问题


$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.';
}

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.


回答1:


try this

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


来源:https://stackoverflow.com/questions/15461765/check-if-username-exist-activated-in-database-using-mysqli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!