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

Asked

Viewed 285 times

0

I don’t know if the question was formulated correctly but anyway... My problem is this:

The user will enter such a code and will click 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 always wanted the url to look like this: meusite.com/pages/track.html? code=$track

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

Example:

The user went to the initial page typed the correct code (123456789) and went to the page meusite.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 was changed only the parameter of the url, thus: meusite.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 related to this new code. Anyway, I just wanted to change the content of the page but to preserve the url template: meusite.com/pages/track.html? code=$track... I thank those who read so far and sorry for the lack of accent, and that my keyboard is in trouble.

  • I know what you mean. It’s a bit long and boring to explain without the look (step-by-step) now but I have the video of my teacher who shows you this: https://www.youtube.com/watch?v=M8lc7LUonQU

1 answer

1


For that you’d have to change your requisition for $_POST for $_REQUEST, capturing, both sent values via POST, like those sent via GET, as long as they have the word code as an index.

Either way this won’t work, for the simple fact that the page in use is .html, which prevents you from using PHP in it, unless you’re using Ajax or something like that you’ll still have this problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.