How to send a variable from one form to another in php?

I want to send a variable from a form called guia_factura_gestion.php and I'm sending it like this:

<?php if($_POST['tipo_guia']=='interna'){      
        $_SESSION['mens'] = 'mens021521';
        echo '<td><input type="text" id="mens" name="mens" size="20" onChange="this.form.submit()" required/><a href="salida_pedidos.php?mens='.$_POST['mens'].'"></td>';

And this is sent to another form called output_out.php how well you can see in the code the problem is that at the time of receiving it I am not receiving it.

Although I am very new to this I am receiving and displaying the variable this way.

<td><?php echo $_POST['mens']?></td>

What Can I do or how can I do to bring such variable?


Hello this is the code of the Form

<?php  
require_once('../validar_logueo.php');
require_once('../mysqli.php');

$sw = 0;
$dis = 'True';
$ped = 'PEDW'.str_pad($_GET['ped'],8,"0",STR_PAD_LEFT);

$sql= "SELECT nit FROM pedidos WHERE id = $_GET[ped]";
$rs = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_row($rs);

$sql = "SELECT COUNT(id) FROM pedidos WHERE nit = $row[0] and estado <> 'Rechazado' and CONVERT(fecha_modificado, DATE) = curdate()";
$rs = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_row($rs);
if ($row[0]>1 && !isset($_POST['tipo_guia'])){
    echo "<script language='javascript'>\n";
    echo 'var si = confirm("Existen '.($row[0]-1).' pedidos de este cliente el dia de hoy.\nDesea generar la Guia para este pedido?"); ';
    echo "if (si == false)\n";
    echo "  window.location='guia_factura.php'\n";
    echo "</script>";
}

if(!isset($_POST['guia'])){
    $_POST['tipo_guia'] = 'envia';
    $_POST['guia'] = '';
}

if(!empty($_POST['guia']) || !empty($_POST['peso'])){
    $sw = 1;
}

mysqli_close($mysqli);
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta http-equiv="CONTENT-TYPE" content="text/html; charset=UTF-8">
    <meta name="description" content="Pedidos Clientes">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="cleartype" content="on" />
    <meta name="MobileOptimized" content="width" />
    <meta name="HandheldFriendly" content="true" />
    <title>SAGYG</title>
    <link rel="stylesheet" href="../css/pedidos.css" />
</head>
<body>
<?php
    if($sw == 1)
        echo'<form name="guia_factura_frm" method="POST" action="guia_factura_bd.php" id="guia_factura_frm" enctype="application/x-www-form-urlencoded">';
    else
        echo '<form name="guia_factura_frm" method="POST" action="guia_factura_gestion.php?ped='.$_GET['ped'].'&fac='.$_GET['fac'].'" id="guia_factura_frm" enctype="application/x-www-form-urlencoded">';

        echo '<form name="guia_factura_frm" method="POST" action="salida_pedidos.php?ped='.$_GET['ped'].'&fac='.$_GET['fac'].'" id="salida_pedidos_frm" enctype="application/x-www-form-urlencoded">';
?>

<fieldset>
<legend>Listado de Facturas por Guia</legend>
<table align="center">
<tr>
    <th align="center">Pedido</th>
    <th align="center">Factura</th>
    <th align="center"></th>
    <?php if($_POST['tipo_guia']=='envia')
            echo '<th align="center">Guia</th>';
          else
            echo '<th align="center">Cajas</th>';
    if($_POST['tipo_guia']=='interna')
            echo '<th align="center">Mensajero</th>';
          else
            echo '<th align="center"></th>';
    ?>
</tr>
<tr>
    <td><input type='text' id='ped' name='ped' size='11' value='<?php echo $ped ?>' style='text-align:center' readonly/></td>

    <td><input type='text' id='fac' name='fac' size='11' value='<?php echo $_GET['fac'] ?>' style='text-align:center' readonly/></td>

    <td><input type="radio" name="tipo_guia" onClick="this.form.submit()" <?=$_POST['tipo_guia']=='envia'?'checked':'';?> value="envia">Envia</td>

        <input type="radio" name="tipo_guia" onClick="this.form.submit()" <?=$_POST['tipo_guia']=='interna'?'checked':'';?> value="interna">Interna<br></td>

    <td><input type='text' id='guia' name='guia' size='11' onChange='this.form.submit()' value='<?php echo $_GET['guia'] ?>' required/></td>
   <?php if($_POST['tipo_guia']=='interna'){      
            $_SESSION['mens'] = 'mens021521';

echo '<td><input type="text" id="mens" name="mens" size="20" onChange="this.form.submit()" required/><a href="salida_pedidos.php?mens='.$_POST['mens'].'"></td>';
        }
   ?>
</tr>
</table>
<center>
    <input type="submit" name="Actualiazar" value="Actualizar">&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;
    <?php
       echo '<a href="guia_factura_gestion.php?ped='.$_GET['ped'].'&fac='.$_GET['fac'].'"><input name="boton" type="button"   class="cambio" value="Limpiar"/></a>';
    ?>
</center>

</fieldset>
<br>
<div align="center"><a href="../menu.php">
<input name="boton" type="button" class="cambio" value="Menu"/></a>&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;
<a href="guia_factura.php"><input name="boton" type="button" class="cambio"value="Atras" /></a>
</div>
</form>
</body>
</html>
 2
Author: Miquel Coll, 2016-09-21

2 answers

You are trying to display a variable $_POST["mens"] which in the first code you put you are declaring it as session variable $_SESSION["mens"] which is not the same.

To access the form data is $_POST["name"]

If the error is not there, confirm that you are declaring the method="post" to your Form

It would be nice if you also put the form code to see if you are trying to access variables that do not exist

 3
Author: Rodrypaladin, 2016-09-22 00:00:32

I think you have the problem in the concept, at least with the code you are showing us. As you have your code, instead of passing the parameter through a form, you are passing it through a link, so you should use $_GET["mens"].

 1
Author: Jose Javier Segura, 2016-09-22 06:35:33