有人可以告诉我为什么该<?php echo $userPasswordError; ?>行不返回任何内容(空),而不是<div class="invalid-feedback">Too long.</div>当我使用以下代码输入包含超过 1 个字符的密码时?
如果我改变这一行:$userPasswordError = '<div class="invalid-feedback">Too long.</div>';
有了这个$userPasswordError = 'Too long.';,就可以了!输出是“太长”。
<?php
$user = $userPassword = '';
$userError = $userInvalid = $userPasswordError = $userPasswordInvalid = '';
$isvalidOrInvalidUser = $isvalidOrInvalidUserPassword = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Verify username.
if (!empty($_POST["user"])) {
if (strlen($_POST["user"]) <= 32) {
$user = $_POST["user"];
$userError = '<div class="valid-feedback">Correct.</div>';
$isvalidOrInvalidUser = 'is-valid';
}
else {
$userInvalid = $_POST["user"];
$userError = '<div class="invalid-feedback">Too long.</div>';
$isvalidOrInvalidUser = 'is-invalid';
}
}
else {
$userError = '<div class="invalid-feedback">Please, add username.</div>';
$isvalidOrInvalidUser = 'is-invalid';
}
// Verify password.
if (!empty($_POST["userpassword"])) {
if (strlen($_POST["userpassword"]) <= 1) {
$userPassword = $_POST["userpassword"];
$userPasswordError = '<div class="valid-feedback">Correct.</div>';
$isvalidOrInvalidUserPassword = 'is-valid';
}
else {
$userPasswordInvalid = $_POST["userpassword"];
$userPasswordError = '<div class="invalid-feedback">Too long.</div>';
$isvalidOrInvalidUserPasword = 'is-invalid';
}
}
else {
$userPasswordError = '<div class="invalid-feedback">Please, add password.</div>';
$isvalidOrInvalidUserPassword = 'is-invalid';
}
}
蝴蝶刀刀
相关分类