PHP echo 未正确返回 <div>

有人可以告诉我为什么该<?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';

  }

}


MYYA
浏览 131回答 1
1回答

蝴蝶刀刀

我终于知道为什么了。&nbsp; $userPasswordError = '<div class="invalid-feedback">Too long.</div>';&nbsp; $isvalidOrInvalidUserPasword = 'is-invalid';的变量名isvalidOrInvalidUserPasword错误,应该是$isvalidOrInvalidUserPassword(缺少sat密码)。如果输入没有 class is-invalid,错误消息将不可见!希望这可以帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5