There is such a code to update the password:

if(isset($_POST['submit'])) { if (empty($_POST['password'])) { header('Refresh: 3; URL = /admin/newpass'); echo '<p class="error">Введите новый пароль!</p>'; } /* elseif (!preg_match('/^(?=.*\d)(?=.*[az])(?=.*[AZ])(?!.*\s).*$/u', $password)) { header('Refresh: 3; URL = /admin/newpass'); echo '<p class="error">Пароль может состоять только из цифр и букв латинского алфавита!</p>'; } */ else { $doc = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $doc->load('xml/admin.xml'); $root = $doc->documentElement; if (isset($_POST['password'])) { $password = $_POST['password']; $pass = $root->getElementsByTagName('password'); if (isset($password['password']) and trim($password['password']) != '') { $pass = $pass->item(0); $pass->nodeValue = crypt($password['password']); } } $doc->save('xml/admin.xml'); header('Refresh: 3; URL = /admin'); echo '<p class="valid">Пароль обновлён</p>'; } } 

This code works fine, but, skips the empty field. That is, if nothing is entered and sent to the server, the “Password updated” is still displayed, while, of course, no recording is made to the file.

It seems to be all logical: there is a condition that the field must be filled in and if everything is OK, then we skip overwriting the file. In general, I can not understand what could be the problem.

    1 answer 1

    The question is solved by such a test:

     if (isset($_POST['password']) && empty($_POST['password']['password']))