在执行查询后将php值放在html字段中

时间:2016-04-17 12:59:08

标签: php html pdo

我想在我的文本框中添加一个我从php查询中获取的值,但是当我这样做时,我想要放在文本框中的值没有设置。有谁知道我怎么做到这一点? 这是我的代码:

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

由于

2 个答案:

答案 0 :(得分:1)

试试这个:

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

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

答案 1 :(得分:0)

设置变量$ 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; ?>"/>