I have the following php code for accessing a database:
$us_usuario = $_POST['us_usuario'];
$us_clave = $_POST['us_clave'];
$statement = mysqli_prepare($con, "SELECT U.us_usuario, U.us_clave, A.hora_inicio, A.hora_fin, A.fecha, A.nombre, A.apellidos, A.prestacion FROM td_agenda_envision A, td_usuario U WHERE U.us_clave = ? AND U.us_usuario = ? AND U.us_ag_alias !='' ");
mysqli_stmt_bind_param($statement,'ss', $us_usuario, $us_clave);
mysqli_stmt_execute($statement);
mysqli_stmt_bind_result($statement, $us_usuario, $us_clave, $hora_inicio, $hora_fin, $fecha, $nombre, $apellidos, $prestacion);
$arrRespuesta = array();
$response['success'] = false;
while(mysqli_stmt_fetch($statement)){
array_push($arrRespuesta, $arrRespuesta['success'] = true);
array_push($arrRespuesta, $arrRespuesta['us_usuario'] = $us_usuario);
array_push($arrRespuesta, $arrRespuesta['us_clave'] = $us_clave);
array_push($arrRespuesta, $arrRespuesta['hora_inicio'] = $hora_inicio);
array_push($arrRespuesta, $arrRespuesta['hora_fin'] = $hora_fin);
array_push($arrRespuesta, $arrRespuesta['fecha'] = $fecha);
array_push($arrRespuesta, $arrRespuesta['nombre'] = $nombre);
array_push($arrRespuesta, $arrRespuesta['apellidos'] = $apellidos);
array_push($arrRespuesta, $arrRespuesta['prestacion'] = $prestacion);
}
echo json_encode($arrRespuesta);
?> When I try it as it is there, it doesn't return anything, not even an error. However, if I comment out the lines:
array_push($arrResponse, $arrResponse['name'] = $name);
array_push($arrResponse, $arrResponse['lastname'] = $lastname);
What is expected comes out: Values displayed for us_usuario="ALICIA" and us_clave="ALICIA"
Any idea why it could be? both first and last names are of the same type of data as the date, however the date does not cause any problem. Here the result of the query directly on the database
From what I see, you have special characters in the "firstname" and "lastname" fields. Surely the encoding of these characters is failing you.
Apache/PHP
Look at this answer .
PHP/MySQL
Look at this answer . Especially the SET NAMES part.
json_encode
You can take a look at the different options that can be passed to
json_encode
at this link .Test:
You can also explicitly encode the data: