These conditions are not observed, it does not display a message, and if it does, it sculpts another message and, of course, puts spaces in the username in the database, the same condition and the second condition enters the base into the database, and if it displays the message, it sculpts other
if (preg_match("/\\s/", $username['username']) && $newusername['newusername'] == true) { echo 'логин не должен содержать пробелов'; } if (empty($username['username']) && $newusername['newusername']) { echo 'пустое поле'; }
Below is the full code
<?php include 'core/init.php'; protect_page(); include 'includes/overall/header.php'; if (isset($_POST['username'], $_POST['newusername'])) { $username = mysql_real_escape_string($_POST['username']); $newusername = mysql_real_escape_string($_POST['newusername']); $sql = mysql_query("SELECT COUNT(username) FROM `users` WHERE `username` = '" . $_POST['newusername'] . "';"); $result = mysql_result($sql, 0); if ($result > 0) { echo "Ошибка, логин существует"; } else { echo (mysql_query("UPDATE `users` SET `username` = '$newusername' WHERE `username` = '$username'")) ? "Данные успешно обновлены!" : "Произошла ошибка при обновлении данных"; } if (preg_match("/\\s/", $username['username']) && $newusername['newusername'] == true) { echo 'логин не должен содержать пробелов'; } if (empty($username['username']) && $newusername['newusername']) { echo 'пустое поле'; } } ?> <h1>пользователи!</h1> <?php $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(); } ?> <form action="" method="post"> <ul> <li>логин*: <br> <input type="text" name="username"> </li> <li>изменить логин*: <br> <input type="text" name="newusername"> </li> <li> <input type="submit" value="сохранить изменения"> </li> </ul> </form> <?php include 'includes/overall/footer.php'; ?>