Using a PHP variable in a text input value = statement

前端 未结 6 1372
走了就别回头了
走了就别回头了 2020-12-15 00:11

I retrieve three pieces of information from the database, one integer, one string, and one date.

I echo them out to verify the variables contain the data.

Wh

相关标签:
6条回答
  • 2020-12-15 00:42

    Try something like this:

    <input type="text" name="idtest" value="<?php echo htmlspecialchars($name); ?>" />
    

    That is, the same as what thirtydot suggested, except preventing XSS attacks as well.

    You could also use the <?= syntax (see the note), although that might not work on all servers. (It's enabled by a configuration option.)

    0 讨论(0)
  • From the HTML point of view everything's been said, but to correct the PHP-side approach a little and taking thirtydot's and icktoofay's advice into account:

    <?php echo '<input type="text" name="idtest" value="' . htmlspecialchars($idtest) . '">'; ?>
    
    0 讨论(0)
  • 2020-12-15 00:43

    I have been doing PHP for my project, and I can say that the following code works for me. You should try it.

    echo '<input type = "text" value = '.$idtest.'>'; 
    
    0 讨论(0)
  • 2020-12-15 00:46

    Solution

    You are missing an echo. Each time that you want to show the value of a variable to HTML you need to echo it.

    <input type="text" name="idtest" value="<?php echo $idtest; ?>" >
    

    Note: Depending on the value, your echo is the function you use to escape it like htmlspecialchars.

    0 讨论(0)
  • 2020-12-15 00:53

    If you want to read any created function, this how we do it:

    <input type="button" value="sports" onClick="window.open('<?php sports();?>', '_self');">
    
    0 讨论(0)
  • 2020-12-15 00:57

    You need, for example:

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

    The echo function is what actually outputs the value of the variable.

    0 讨论(0)
提交回复
热议问题