What I'm trying to do is change the usernames in a DB, but provide an error if the new username already exists. It's updating fine, but the check to see if the username already exists doesn't seem to be functioning. Here's the code:
$sql = "SELECT * FROM ".$db_table_prefix."Users";
$users = $db->sql_query($sql);
$errors = array();
while($row = $db->sql_fetchrow($users)) {
$newusername = $_POST[$usernameID];
if (in_array($newusername,$row)){
$errors[] = "Unable to change ".$row['Username']."'s name because selected username is already in use.";
}
else{
$sql = "UPDATE ".$db_table_prefix."Users SET Username = '".$newusername."', Username_clean = '".sanitize($newusername)."' WHERE User_ID='".$row['User_ID']."'";
$db->sql_query($sql);
}
}
As you can see, the check is being performed by an "in_array" check of array "$row". The interesting thing is that if I replace the variable $newusername simple with the string of one of the names in the DB, it works just fine. But for some reason, when I use a variable there instead it simply ignores the function and doesn't give either a true or a false return. Does the "in_array" function not support variables as the search string? Or have I done something wrong?
Any help would be appreciated.