I currently have this code that I wrote up:
$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'];
}
However it seems to just completely ignore this and even if the username is identical (capitals and such) it will still allow the user to register making 2 of the same users. My database looks like this:
http://puu.sh/1mTcZ/9b2ff3b68f44b4cc486beacc2d2b88fd
I cant seem to get this working at all. The database structure looks like this:
refined (dbname) > users (table) > username (row)
Any help is very much appreciated.
Edit:
After a few changes this is what I have, however I still seem to be having the same issues.
$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'];
}
The username row is also now utf8_general_ci
Ok, I’ll post my comment as an answer.
Your IF statement is evaluating the incorrect variable. It should be evaluating $countUsername, not $checkUsername.
Also, you seem to be initializing your errors array incorrectly. Try:
I’ve tested this on my database and it works.