pass a variable from one php file to another

0

I need to pass my variable $ _process of my document save.php to datos.php by URL

I have the following in guardar.php

<?php
require_once 'conexion.php';
$_Proceso = $_POST["Proceso"];
$_Actividades = $_POST["Actividad"];
$_Entrada = $_POST["Entrada"];
$_Salida = $_POST["Salida"];
$query = "INSERT INTO proceso (Nombre_proceso,actividades,entrada, salida)
VALUES ('$_Proceso', '$_Actividades', '$_Entrada', '$_Salida'); ";
$result = $conn->query($query);
if (!$result) die($conn->error);
header("Location: ../form_validation.php?$_Proceso=$_Proceso");
exit;
?>

and I have this is my data.php file

<?php
require_once 'PHP/login.php';
 
              $_proceso = $_GET['$_Proceso'];
              $_query = "SELECT id,Nombre_proceso FROM proceso WHERE Nombre_proceso = '$_proceso'";
                $_result = $conn->query($_query);
                if (!$_result) die($conn->error);
 
                while ($_row = mysqli_fetch_array($_result)){
                    $_proceso = $_row["Nombre_proceso"];
                    $_id = $_row["id"];
                        }
              ?>

but it gives me the following error "Notice: Undefined variable: _Process"

    
asked by antonio sanchez 07.06.2018 в 23:22
source

3 answers

1

Your error lies in the name of the variable. You have previously declared $ _Process and when doing header ("$ _ Process = $ _ Process") it is replaced by the value of the declared variable. It would remain as a header ("Value = Value").

    
answered by 07.06.2018 / 23:53
source
0

As Lucasato says, there is something that does not fit with your POST. in your file, save.php replace

header("Location: ../form_validation.php?$_Proceso=$_Proceso");

for

header("Location: ../form_validation.php?proceso=" . $_POST['Proceso']);

In your file datos.php collect your variable as well

$proceso = $_POST['proceso'];

If it does not work for you, you can check out cURL

    
answered by 08.06.2018 в 00:27
0

Exactly as Lucasato says it is solved by changing the line

header("Location: ../form_validation.php?$_Proceso=$_Proceso");

By

header(‘Location: ../form_validation.php?$_Proceso=‘.$_Proceso);

If there is a variable within double quotes, when it is executed, it is changed to the value, so that as it says "lucasato" the result is value = value

    
answered by 08.06.2018 в 00:18