Show a DIV and hide another if the parameter in the url is a default parameter

0

I do not know if the question was formulated correctly but anyway ... My problem is this:

The user will enter such a code and click on search. This request will go through a PHP that will check if this code is present in the code.txt file and open a page with a table containing data related to the code or open an error page if the code is incorrect:

$track = $_POST['code'];
$codigo = file_get_contents("codes.txt");
$codigo = explode(PHP_EOL, $codigo); // PHP_EOL is for a line break
if(in_array($track, $codigo)){
header("LOCATION: pages/track.html?code=$track");
} else {
header("LOCATION: pages/error.html");
}

My problem is that I wanted the url to always look like this: myite.com/pages/track.html?code=$track

Just changing the parameter ($ track), otherwise I would have to create a page for each code. And every different code / parameter would display a DIV containing one table and hide the other.

Example:

The user was on the initial page typed the correct code (123456789) in the search box and went to page myite.com/pages/track.html?code=123456789 showing in a table the data referring to that code and on the same page he typed another correct code (111222333) and just changed the url parameter, so: myite.com/pages/track.html?code=111222333. And along with the new parameter was hidden the other table and shown the new table that contains the data referring to this new code. Anyway, I just wanted to change the content of the page but preserved the url template: myite.com/pages/track.html?code=$track ... I thank those who have read here and apologize for the lack of accent , and that my keyboard is in trouble.

    
asked by anonymous 14.10.2015 / 21:34

1 answer

1

For this you would have to change your request from $_POST to $_REQUEST , which captures both the values sent through POST and those sent via GET provided they have the word code as the index.

In any case this will not work, just because the page in use is .html , which prevents you from using PHP on it, unless you are using Ajax or something like this you will continue to have this problem.

    
15.10.2015 / 01:42