How to fix this error $_SESSION:Notice: Undefined offset: 0
-
Hi sorry I am just a baby in PHP. I want to get the value of $_SESSION['username'] but it gives me this error : Notice: Undefined offset: 0. Please see my code below. Your help will be greatly appreciated. Thanks. "; echo $_SESSION[0]; //I want an output "andrew" but it fails.
-
Hi sorry I am just a baby in PHP. I want to get the value of $_SESSION['username'] but it gives me this error : Notice: Undefined offset: 0. Please see my code below. Your help will be greatly appreciated. Thanks. "; echo $_SESSION[0]; //I want an output "andrew" but it fails.
$_SESSION
(see PHP: $_SESSION - Manual[^] ) is an associative array containing key value pairs (see PHP: Arrays - Manual[^]). These are not accessed by an index but by their keys which might be integers or strings. Because you have not assigned a value with the key '0' you will get the error. Just use the key instead:echo $_SESSION['username'];
-
$_SESSION
(see PHP: $_SESSION - Manual[^] ) is an associative array containing key value pairs (see PHP: Arrays - Manual[^]). These are not accessed by an index but by their keys which might be integers or strings. Because you have not assigned a value with the key '0' you will get the error. Just use the key instead:echo $_SESSION['username'];