我目前有我写的这段代码:
$username = $_POST['username'];
$password = $_POST['password'];
$rpassword = $_POST['rpassword'];
$usrip = $_SERVER['REMOTE_ADDR'];
$email = $_POST['email'];
$errors = array();
$checkUsername = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username");
$checkUsername -> execute(array(':username' => $username));
$countUsername = $checkUsername -> fetchColumn(0);
if ($checkUsername != 0)
{
$errors['Username is already taken'];
}
然而,它似乎完全忽略了这一点,即使用户名相同(大写等),它仍然允许用户注册 2 个相同的用户。我的数据库如下所示:
http://puu.sh/1mTcZ/9b2ff3b68f44b4cc486beacc2d2b88fd
我似乎根本无法让它工作。数据库结构如下:refined (dbname) > users (table) > username (row)
很感谢任何形式的帮助。
编辑:
经过一些更改,这就是我所拥有的,但是我似乎仍然遇到同样的问题。
$checkUsername = $odb->prepare("SELECT COUNT(*) FROM `users` WHERE LOWER(`username`) = :username");
$checkUsername -> execute(array(':username' => $username));
$countUsername = $checkUsername -> fetchColumn(0);
if ($checkUsername != 0)
{
$errors['Username is already taken'];
}
用户名行现在也是 utf8_general_ci