【问题标题】:Php echo in php inside input tagphp 在输入标签内的 php 中回显
【发布时间】:2016-01-24 13:33:07
【问题描述】:

我怎样才能添加这个value="'echo $_SESSION['module'];'" 在会话中显示值

<?php
if ($_SESSION['role'] == "normalUser"){
   echo '<div class="form-group">
 <input required type="text" name="indeks" id="indeks" class="form-
 control input-lg" placeholder="Индекс" value="'echo $_SESSION['module'];'" tabindex="1">
        </div>';
  }?>

【问题讨论】:

  • 你不能echoecho。连接或关闭回声。

标签: php input tags echo


【解决方案1】:

你需要使用字符串连接。

<?php
if ($_SESSION['role'] == "normalUser"){
   echo '<div class="form-group">
 <input required type="text" name="indeks" id="indeks" class="form-
 control input-lg" placeholder="Индекс" value="' . $_SESSION['module'] . '" tabindex="1">
        </div>';
  }?>

【讨论】:

    【解决方案2】:

    最好尽可能在 PHP 之外使用 HTML:

    <?php
    if ($_SESSION['role'] == "normalUser"){
    ? >
     <div class="form-group">
     <input required type="text" name="indeks" id="indeks"  class="form-control input-lg" placeholder="Индекс" 
    value="<?=$_SESSION['module'];?>"  tabindex="1">
    </div>
    <?php
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多