+ 1
Changing html code with php on different pages
Is changing html h1 tags with php a good idea I m working on this code but I get errors if I don't put isset function but if I include it it doesn't work <?php $pagina = isset($_GET['PageName']); if ($pagina=="post") { echo "<h1>Posts page</h1>"; }elseif ($pagina=="about") { echo "<h1>About me</h1>"; } elseif ($pagina=="contact") { echo "<h1>Contact me</h1>"; }else{ echo "<h1>First Blog</h1>"; } ?>
1 Odpowiedź
+ 2
The `isset` function returns a boolean state indicating whether a variable value has been initialized (true = initialized, false = not initialized). We use it to avoid referencing a non existing or uninitialized variable. For example, `if (isset($user_name)) // do something`.
In your code, you assign the `isset` return value into variable <$pagina>, but I think you meant to assign $_GET['PageName'] instead. 5o, rather than:
$pagina = isset($_GET['PageName']);
I think you actually meant this:
$pagina = $_GET['PageName'];
P.S. In case you didn't know yet, Code Playground currently doesn't have support for form submission. Checking for $_GET or $_POST is pointless. Unless you're doing this on your own machine/server.
Hth, cmiiw