

PHP ověření zdali je uživatel v databázi
Dobrý den, mám stránku kde se registrují uživatelé registrace.php:
<?php
include('chat/lib/data/users.php';
//check existing users
if ($_POST['username'])
{
//if user entered a name
}
//collect information from users.php
$user_amount = count($users);
for ($i=0; $i <=$user_amount;$i++);
{
//check usage of name
if (strtolower($_POST['username']) == strtolower($users[$i]['userName']))
$username_used = 1;
}
//make sure user chose a password
if (!$_POST['password'])
$password_error = 1;
//ensure username avalible and password chosen
if (!$username_used and!$password_error)
{
//present user id accepted message
print '<br>Účet '.$_POST['username'].' byl vytvořen...<br><br> Můžete se přihlásit<br><br><br><br><br><br>';
$next_user = $user_amount++;
$new_user_information = '
//remote created from '.$_SERVER['REMOTE_ADDR'].'
$users['.$next_user.'] = array();
$users['.$next_user.'][\'userRole\'] = AJAX_CHAT_USER;
$users['.$next_user.'][\'userName\'] = \''.$_POST['username'].'\';
$users['.$next_user.'][\'password\'] = \''.$_POST['password'].'\';
$users['.$next_user.'][\'channels\'] = array(0,1);
?>';
$file_edit = fopen('chat/lib/data/users.php', 'r+';
fseek($file_edit, -3,SEEK_END);
fwrite($file_edit, $new_user_information);
fclose($file_edit);
}
//end of php
?>
<table border="0">
<table border="0">
<tr>
<td><h2>Registrace</h2></td>
</tr>
<tr>
<td>
<!- collect username and password information via form ->
<form action="" method="post">
Uživatelské jméno:<br><input name="username" type="text" value="" /> Max. 16 znaků<br>
Heslo:<br><input name="password" type="text" value="" /><br>
<input name="submit" type="submit" value="Vytvořit účet" />
</form>
</td>
</tr>
</table>
</table>
A stránku kde se zapisují data registrace, users.php: <?php
/*
* @package AJAX_Chat
* @author Sebastian Tschan
* @copyright (c) Sebastian Tschan
* @license GNU Affero General Public License
* @link [url]https://blueimp.net/ajax/[/url]
*/
// List containing the registered chat users:
$users = array();
// Default guest user (don't delete this one):
$users[0] = array();
$users[0]['userRole'] = AJAX_CHAT_GUEST;
$users[0]['userName'] = null;
$users[0]['password'] = null;
$users[0]['channels'] = array(0);
//remote created from 89.202.224.76
$users[5] = array();
$users[5]['userRole'] = AJAX_CHAT_USER;
$users[5]['userName'] = 'Lukccaa';
$users[5]['password'] = 'aaaaaaaa';
$users[5]['channels'] = array(0,1);
//remote created from 89.202.224.76
$users[6] = array();
$users[6]['userRole'] = AJAX_CHAT_USER;
$users[6]['userName'] = 'Lukccaa';
$users[6]['password'] = 'bbbbbbbb';
$users[6]['channels'] = array(0,1);
//remote created from 89.202.224.76
?>
Problém je že když se zaregistruji 2x se stejnou přezdívkou a dám jiné heslo tak se mohu přihlašovat obouma účtama. Co mám doplnit aby se při registraci pokud je jméno již zaregistrované oběvilo "Tato přezdívka je obsazena" . Případné info ještě doplním. Snad jsem to napsal srozumitelně. Děkuji Vám za odpověď