The following code return some results that are baffling me...
if(is_array($loginUser)) {
$_SESSION['name'] = $loginUser['firstname'];
$_SESSION['id'] = $loginUser['id'];
print_r($_SESSION['name']);
print_r($loginUser);
var_dump($loginUser[1]);
exit();
header("Location: ../index.php?page=home");
}
That returns:
Notice: Undefined index: firstname in wwwroot/includes/userhandler.php on line 124
Notice: Undefined index: id in wwwroot/includes/userhandler.php on line 125
Array ( [0] => Array ( [0] => 4 [id] => 4 [1] => Johnny [firstname] => Johnny [2] => Appleseed [lastname] => Appleseed [3] => ja@ja.com [email] => ja@ja.com [4] => johnny'shashedpassword [password] => johnny'shashedpassword ) )
Notice: Undefined offset: 1 in wwwroot/includes/userhandler.php on line 129
NULL
The id
and firstName
are stored in an array with key 0
change
$_SESSION['name'] = $loginUser['firstname'];
$_SESSION['id'] = $loginUser['id'];
to
$_SESSION['name'] = $loginUser[0]['firstname'];
$_SESSION['id'] = $loginUser[0]['id'];
but I see no reason why the you have an extra dimension in your $loginUser
array. Try to refactor the way $loginUser
is building its array
Later in the code you are calling var_dump($loginUser[1]);
This returns your second error message because there is only a $loginUser[0]
Your array is in another array. You can solve this by using the following line of code:
$loginUser = current($loginUser);
Furthermore, when using var_dump
I always find it easy to use <pre />
tags. This makes it easier for you to see how the array is built up.
Example:
echo "<pre>";
var_dump($loginUser);
echo "</pre>";
exit;