简体   繁体   中英

set textbox value with php variable

I'm using php 7 . I trying to put php variable value into html textbox, but it doesn't work.

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <form action="two.php" method="POST">
            <input type="text" name="id_brg" value="<?php echo $_GET['id_brg'] ?>">
        </form>
    </body>
</html>

two.php

<?php 

$id_brg = $_POST[uniqidi()];

?>

I'm not entirely sure what you're trying to do. But I'm pretty sure you want to set the value of a form field to a value from the URI query string.

The way you've done this is correct in the first snippet is correct, but your issue is that you're using POST and not for your form method. Here is how you should do it if you want it for both types.

<?php
    if ($_POST['id_brg']) {
        $id_brg = $_POST['id_brg'];
    } else if ($_GET['id_brg']) {
        $id_brg = $_GET['id_brg'];
    } else {
        $id_brg = uniqid();
    }

?>

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <form action="two.php" method="POST">
           <input type="text" name="id_brg" value="<?php echo $id_brg; ?>">
        </form>
    </body>
</html>

Consider use POST method on your form.

<input type="text" name="id_brg" value="<?php echo $_POST['id_brg']; ?>">

You miss semicolon on the code you provide below.

$_POST['id_brg'];

one.php

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
       <input type="text" name="id" value="
       <?php
       include 'two.php';
       echo $id_brg;

       ?> "
       >
</body>
</html>

two.php

<?php 

   $id_brg = uniqid();

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM