Return result to an input value in action to another php file

0

I am looking for that when processing in response.php it returns the value to the previous page to locate it in the input. I think this could solve it using $ global but I do not understand its operation much and I already read that it is not advisable.

<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
    <title></title>
</head>
<body>
  <form  action="respuesta.php" method="post">
    <select class="" name="select">
      <option value="1">1</option>
    </select>
    <input type="text" name="" value="<?php if (isset($M_codigo)){echo $M_codigo;}  ?>">
    <input type="submit" name"" value="enviar">
  </form>
</body>
</html>

In response php convert and return the value to the input

<?php
  if ($_POST["select"]=="1") {
    $M_codigo="Valor_devuelto"; 
  }

 ?>
    
asked by Sebastian Ismael 01.12.2018 в 20:29
source

1 answer

1

It depends on how you get from the second page to the first page, but one idea is to use sessions ($ _SESSION).

If I understood you correctly, what you would have to do would be:

In response.php you assign the value that interests you to a session variable.

$_SESSION['valor'] = $_POST["select"];

In the first of the forms:

if(isset($_SESSION['valor'])){
  $valor = $_SESSION['valor'];
else
  $valor = '';

...

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

And do not forget that when using session variables, you should always initialize the session as soon as you open the keys, before any other thing in your PHP file, that is:

<?php
session_start();

Do some search by Google to understand them. They are very useful.

    
answered by 01.12.2018 / 20:51
source