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

后端 未结 8 1894
无人共我
无人共我 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:41

    Here's one that i wrote:

    $error = false;
    $sql= "SELECT username FROM users WHERE username = '$username'";
    $checkSQL = mysqli_query($db, $checkSQL);
    
    if(mysqli_num_rows($checkSQL) != 0) {
       $error = true;
       echo 'Username taken.';
    }
    

    Works like a charm!

提交回复
热议问题