I really do not understand how you are operating, you must understand that by using the header("Location: ...")
you are sending the user the necessary information in the HTTP header so that your browser knows where to point, in other words the client ( browser) who redirects taking into account the information you provided through the header:
link
... header () is used to send raw HTTP headers.
"Location:" Not only sends the header to the browser, but also returns the status code (302) REDIRECT to the browser unless the status code 201 or 3xx has already been sent.
Knowing the above, then you can deduce that it is not equivalent to include the file, as you would with require
or include
Assuming you have these two files:
- principal.php
<?php
$miVariable = "hola mundo";
header("archivo-final.php");
- final-file.php
<?php
echo $miVariable;
You will notice that when executing the file principal.php
you finally end up also executing the archivo-final.php
with the following error message is:
Notice: Undefined variable: myVariable in final-file.php on line ...
This is because what is really happening, is not that you call your file archivo-final.php
from principal.php
, but you have told the user that once you have the server's response regarding the query principal.php
direct to archivo-final.php
, it's as if the user himself wrote the URL of archivo-final.php
directly in the navigation bar ( two independent queries ). Now if the above is clear and right to think that you are trying to use the variable $datos
in the file mostrarEstadistica.php
, that would be your problem, it would be enough to edit the header
for a require
or include
, as well :
elseif($_POST['tipo']=='medico')
{
if($medico->filtroMed($_POST['rut']))
{
$_GET['med'] = 'si';
}
else
{
$_GET['med'] = 'si';
}
require('__RUTA_VISTA__/mostrarEstadistica.php');
}
Edit the code slightly, since regardless of whether the filter is fulfilled or not, you always execute the line that calls to the view and the only thing that changes is the attribute $_GET
that you send to it. Therefore, it is not worthwhile to include it in the conditional.
To consider:
-
__RUTA_VISTA__
is the relative or absolute path of the directory that stores to show Statistics.php.
- I do not think it's optimal to directly use the global variables
$_POST
and $_GET
in fact the use $_GET
is unnecessary in this case, but I try to maintain the current structure. Regarding access to global variables you can use filter_input (...) but it is another theme.