mardi 19 août 2014

Better Way to Check SQL entries for Case-Sensitive Entries


Vote count:

0




Background


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?


CODE:



...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>";


asked 2 mins ago







Better Way to Check SQL entries for Case-Sensitive Entries

Aucun commentaire:

Enregistrer un commentaire