I have a web program which has an administrator panel that allows the current logged in user to add new logins and passwords into the system for other users. While working on some code, it had occurred to me that although I check for the same 'first' and 'last' names, as well as same 'username' in the system, I do not currently check for the user 'Bilbo Baggins' as should 'bilbo baggins' be checked.
In theory, I could do two times the checking of all similarities... whether he be 'bilbo baggins', 'bILBO BaggINS' or 'BILBO BAGGINS'... But I presume there would be a better way to do this rather than rewriting the same code to check over and over the same information.
Using my current implementation, does someone have a similar situation to check 1) the same first name and last name are not reserved in the system, and 2) the same username does not exist?
...set all variables used in post...
try {
//Confirm that there are no other same first and last names with the same registration
$query = $general->db->prepare("SELECT * FROM users WHERE firstname = :firstname AND lastname = :lastname");
$names = array(
'firstname' => $firstname,
'lastname' => $lastname);
$query->execute($names);
$result = $query->fetchAll();
if (sizeof($result) == 0) {
//Now check that the username isn't currently in use
$query = $general->db->prepare('SELECT * FROM users WHERE username = :username');
$username = array('username' => $username);
$query->execute($username);
$usernames_exist = $query->fetchAll();
if (sizeof($usernames_exist) == 0) {
##both fullname test as well as username check passed, so allow user to enter the information
$addedUser = $users->register_user($firstname, $lastname, $username['username'], $password, $cellphone, $seclvl, $email, $direct, $extension);
$message = "Congratulations, you have successfully added **AN ALREADY ACTIVATED** user with the following information: <br><br>";
MySQL WHERE clauses are case insensitive by default. So...
...are all only going to find the one record containing 'bilbo_baggins' in the db. Just make sure that field has a UNIQUE index.
See here for more info.
For your system to function well you need to not check on first / last name. But now to get back on point.
What you can do is have all of the text in lower case form it enters the database. Once you pull it out you can format the text into the correct form.
This allows all of your data to function in the same way so you don't have to have so many checks.