There is a form through which I change my login, but if I already have such a login and write it again for newusername, then there will be two identical logins in the database, why does the commented condition not work?
<?php include 'core/init.php'; protect_page(); include 'includes/overall/header.php'; if (empty($_POST) === false) { $required_fields = array( 'username', 'newusername' ); foreach ($_POST as $key => $value) { if (empty($value) && in_array($key, $required_fields) === true) { $errors[] = 'поля со звездочкой обязательны'; break 1; } if (user_exists($_POST['username']) === ($_POST['newusername'])) { $errors[] = 'этот логин \'' . $_POST['username'] . '\' используется'; // условие которое должно выводить ошибку и не обновлять логин в БД если такой есть } } } ?> <h1>пользователи!</h1> <?php if (isset($_POST['username'], $_POST['newusername'])) { $username = mysql_real_escape_string($_POST['username']); $newusername = mysql_real_escape_string($_POST['newusername']); mysql_query("UPDATE `users` SET `username` = '$newusername' WHERE `username` = '$username'"); } $ath = mysql_query("SELECT * FROM `users` WHERE `type`=0"); if ($ath) { // Определяем таблицу и заголовок echo "<table border=1>"; echo "<tr><td>user_id</td><td>логин</td><td>пароль</td><td>имя</td><td>email</td></tr>"; // Так как запрос возвращает несколько строк, применяем цикл while ($author = mysql_fetch_array($ath)) { echo "<tr><td>" . $author['user_id'] . " </td><td>" . $author['username'] . " </td><td>" . $author['password'] . "   </td><td>" . $author['first_name'] . " </td><td>" . $author['email'] . "   </td></tr>"; } echo "</table>"; } else { echo "<p><b>Error: " . mysql_error() . "</b><p>"; exit(); }