目前,我有這個代碼,我寫了:不過它似乎只是完全忽略這一點,即使用戶名是相同的(資本和這樣)檢查,如果用戶名已存在
$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
我似乎無法得到這個工作的。數據庫結構如下所示: 精確(dbname)>用戶(表)>用戶名(行)
任何幫助非常感謝。
編輯:
一些變化,這是我有後,但我仍然似乎有同樣的問題。
$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
您的IF語句評估($ checkUsername!= 0)。不應該這樣($ countUsername!= 0)? –