1

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()];

?>
13
  • if your method in the form is POST you can't use $_GET to take the value... you should use $_POST['id_brg'] Commented Nov 27, 2017 at 10:40
  • i did, but it doesn't work too Commented Nov 27, 2017 at 10:44
  • 1
    your first page is in .html or in .php.? Commented Nov 27, 2017 at 11:04
  • 1
    save it with .php extension Commented Nov 27, 2017 at 11:05
  • 2
    @GyandeepSharma thanks ... I got what I wanted Commented Nov 27, 2017 at 11:28

3 Answers 3

1

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'];
Sign up to request clarification or add additional context in comments.

3 Comments

i correct the code but still ..showing "<?php echo $_GET['id_brg']; ?>" i my textbox
@usersaturintan are you sure both of your file using .php ?
yup, I have fixed it
1

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>

4 Comments

it have same problem with me .. textbox only display "<?php echo $id_brg ?>" not the uniqid()
Make sure you're file is a PHP file, and not an HTML one. That sounds like the file isn't being runt through the pre-proccessor.
if i save html file in php, do i need to <?php ?> tag at the beginning and the end of tag html ?
yes. The difference between a .html and .php file is only that the code written between <?php and ?> get's run. PHP code will not be processed in a .html file, only a .php one.
0

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();

?>

8 Comments

Rintan, achieving only the result should not be the goal in the world of coding, try to learn the better approach too. As you are newbie I would love to help you learn the better ways so that it helps in developing the good base.
okk .. teach me how to write the right code with the same result bcz i have no idea to create the result like that with better code :')
For that, you have clear me exactly what you want to achieve? What's the scenario you are writing code for. Kindly explain to me that, then only I can tell you the better approach.
i mean maybe i can compare yours and mine, so maybe i can learn something from the beauty of your code
Until and unless you clear your requirement I can't write a better code. kindly explain what you want to achieve?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.