0
I would like to know how I return more than one property in PHP. Below is the code where I return the user name and wanted to return, in addition, his registration. I tried to do the same by adding the 'license plate', but it didn’t work.
<?php
include('connect.php');
session_start();
if($_SESSION['logado']) {
$nome = $_SESSION['nome'];
//$matricula = $_SESSION['matricula'];
}
echo json_encode(array('nomeUsuario' => $nome));
//'matricula' => $matricula));
?>
how did you try? Using
echo json_encode(array('nomeUsuario' => $nome, 'matricula' => $matricula));
should work.– Oeslei
That, Oeslei. I tried that way.
– Marcelo Augusto
Maybe your variable
$_SESSION['matricula']
is empty? What response does the browser receive (see directly in the browser console)?– Oeslei
In the console is returned the name of the user right, but the registration appears null.
– Marcelo Augusto
But does the right registration field appear? Have the value
null
does not mean that it is not working. As I said in the other comment, its variable$_SESSION['matricula']
must be empty.– Oeslei
The registration field appears, but in my database the registration field is not empty...
– Marcelo Augusto
Put your command on
echo
in this way:echo json_encode($_SESSION);
and analyze all fields of your Session. Even if the registration is correct in the database, maybe your script to set the Session has an error.– Oeslei
All the fields showed up except for the license plate..
– Marcelo Augusto
gives a
print_r
to see if the license plate is on$_SESSION
– Wallace Maxters
The license plate didn’t show up on
print_r
,– Marcelo Augusto
If enrollment is non-existent in SESSION, then the hole is lower.. Look in the script that creates SESSION, because that’s where the problem should be..
– Daniel Omine