php - get curent class in sidebar ($_GET['do'] == "")
In my sidebar is class added for active link with this code:
<?php echo ($_GET['do'] == "") ? "class=\"current\"": "";?>
// This is root link
All working but I have error in my error_log file....
This is in next menu item:
<?php echo ($_GET['do'] == "add_account") ? "class=\"current\"": "";?>
Also working but without error!! So I need something add into "" ?Or how can I better make root link mark in menu with php ?
Thanks for opinions!! Regards Makromat
Answer
Solution:
Check if it exists and then check which value it holds.
Answer
Solution:
Accessing variables (or array indexes, or object properties) which do not exist (yet) in PHP triggers a
Notice
(not an error). This is the case when you access$_GET['do']
, which does not exist.In order to fix that, replace:
With:
The same applies everywhere a variable (or array index, or object property) which might not exist. So when you're checking
$_GET['do']
for equality with either""
or"add_account"
you need to first check ifisset($_GET['do'])
.Which means you also need to edit the second occurrence of
$_GET['do']
in your code:Becomes:
Like @Houssni said.