【问题标题】:Echo input in PHP [closed]PHP中的回声输入[关闭]
【发布时间】:2013-04-09 09:02:42
【问题描述】:

有人可以帮我解决这个问题吗?我试图在 php 中使用 isset 作为值来回显输入,但我在使用逗号时遇到了困难。

echo '<td><input class="text" type="text" id="txtLogin" name="txtLogin" value="<?= isset($_POST['"txtLogin"']) ? htmlspecialchars($_POST['"txtLogin"']) : '' ></td>';

谢谢!

【问题讨论】:

  • 您不再需要 PHP 脚本的开始标签。 &lt;?=isset() 之前是错误的。 = 符号表示echo,现在你有:echo "some string&lt;?php echo 'another string'" 等等......这是错误的。使用点分隔字符串和 PHP 代码,例如echo 'String '. some_php_stuff() . 'another string';

标签: php html input echo isset


【解决方案1】:

更清洁的解决方案是:

$txtLogin = isset($_POST['"txtLogin"']) ? htmlspecialchars($_POST['"txtLogin"']) : "";
echo '<td><input class="text" type="text" id="txtLogin" name="txtLogin" value="'. $txtLogin .'"></td>';

这很好,而不是在引号内添加条件语句

【讨论】:

    【解决方案2】:

    你可以试试这个。

    <?php
    echo '<td><input class="text" type="text" id="txtLogin" name="txtLogin" value="' . isset($_POST['txtLogin']) ? htmlspecialchars($_POST['txtLogin']) : '' . '></td>';
    ?>
    

    【讨论】:

    • 值的双引号后缺少单引号
    【解决方案3】:

    试试这个

    echo '<td><input class="text" type="text" id="txtLogin" name="txtLogin" value="'.isset($_POST['"txtLogin"']) ? htmlspecialchars($_POST['"txtLogin"']) : "".'"></td>';
    

    【讨论】:

      【解决方案4】:

      你可以像这样连接字符串和表达式:

      echo '<td><input class="text" type="text" id="txtLogin" name="txtLogin" value="' . (isset($_POST['"txtLogin"']) ? htmlspecialchars($_POST['"txtLogin"']) : '') . '"></td>';
      

      【讨论】:

      • @Manuel。 value 应该有一个结束双引号
      • @Sabari 你说得对,谢谢。固定
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      相关资源
      最近更新 更多