Trying to check if username already exists in MySQL database using PHP

后端 未结 8 1929
无人共我
无人共我 2020-12-28 10:12

I\'ve looked at the many other posts that were similar to my issue and implemented their solutions (as far as I can tell) as exactly as I could. However, every time I execut

8条回答
  •  长情又很酷
    2020-12-28 10:52

    Everything is fine, just one mistake is there. Change this:

    $query = mysql_query("SELECT username FROM Users WHERE username=$username", $con);
    $query = mysql_query("SELECT Count(*) FROM Users WHERE username=$username, $con");
    
    if (mysql_num_rows($query) != 0)
    {
        echo "Username already exists";
    }
    else
    {
      ...
    }
    

    SELECT * will not work, use with SELECT COUNT(*).

提交回复
热议问题