I am trying to get a value from a URL and it's not working. Here is the code:
<?php
if (isset($_GET['pag'])) {
$sel_continut = $_GET['pag'];
} else {
$sel_continut = "no value sent";
}
echo "<a href=\"continut.php?pag=" . $informatie_tabel['nume_meniu'] . "\">" . $denumire_pagina . "</a> <br />";
Can someone help me understand what I'm doing wrong?
In response to your comments...
This is the URL being used to load the page:
Note that there is no query string value. So this code:
isn't going to find anything. The value was never set. So your code is always going to enter the
else
condition. You later create a link with a query string value:But that's for a completely different page which hasn't even been requested yet. If you reference
$_GET['pag']
on thecontinut.php
page's code, then you'll see the value.What I'm trying to say is... You can't read a query string value before it's been sent. The good news is that you don't need to read this value. Since you're in the same code which sets the value on the link, then clearly you already have this value. Right here: