简体   繁体   English

用php变量设置文本框值

[英]set textbox value with php variable

I'm using php 7 . 我正在使用php 7 I trying to put php variable value into html textbox, but it doesn't work. 我试图将php变量值放到html文本框中,但是不起作用。

<!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 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. 但我很确定您要将表单字段的值设置为URI查询字符串中的值。

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. 在第一个代码段中,这样做的方法是正确的,但是您的问题是您使用的是POST,而不是表单方法。 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. 考虑在表单上使用POST方法。

<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 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 two.php

<?php 

   $id_brg = uniqid();

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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