Usa il WHERE
clausola per ottenere solo le righe con il nome utente specificato:
"SELECT * FROM user_list WHERE uname='".$server->real_escape_string($uname)."'"
Quindi controlla se la query determina la selezione di righe (0 o 1 riga) con MySQLi_Result::num_rows
:
function createUser($uname,$pword) {
$server->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$result = $server->query("SELECT * FROM user_list WHERE uname='".$server->real_escape_string($uname)."'");
if ($result->num_rows() === 0) {
if ($server->query("INSERT INTO user_list (uname) VALUES ('".$server->real_escape_string($uname)."'")) {
echo "User added Successfully";
} else {
echo "Error while adding user!";
}
} else {
echo "User already exists!";
}
}