【问题标题】:Put php value in html field after query has been executed执行查询后将 php 值放入 html 字段
【发布时间】:2016-08-09 04:16:55
【问题描述】:

我想在我的文本框中输入一个从 php 查询获得的值,但是当我这样做时,我想在我的文本框中输入的值没有设置。有谁知道我该怎么做? 这是我的代码:

Nom : <input type="text" name="nom" value="<?php if(isset($nom)){echo htmlspecialchars($nom);} ?>"/>

谢谢

【问题讨论】:

  • 嗯,如果没有设置值 - 然后设置它们。
  • 那是因为$nom 不是。你可以这样做:...value="&lt;?php if(isset($_POST['nom'])){ echo $_POST['nom']; } ?&gt;"...
  • 这似乎没问题,只要设置了 $nom

标签: php html pdo


【解决方案1】:

试试这个:

    <?php 
    $nom = $_POST['nom'];
    if (isset($nom)){ 
        $new = htmlspecialchars($nom);
    } 
    ?>

    <input type="text" name="nom" value="<?php echo $new; ?>" />

【讨论】:

    【解决方案2】:

    设置变量$nom

    <?php 
    // If the variable in the query is $nom, then
    $nom = isset($nom) ? htmlspecialchars($nom) : '';
    
    // If $nom is a POST variable, then
    $nom = isset($_POST['nom']) ? htmlspecialchars($_POST['nom']) : '';
    ?>
    
    Nom : <input type="text" name="nom" value="<?php echo $nom; ?>"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多