I am in doubt on a code I am developing, I am passing a query on the MySql database and I need this response to return in JSON for angularJS to understand and write in HTML.
Follow the code:
<?php
header('Content-Type:text/html;charset=UTF-8');
include("../class/conexao.class.php");
$myData = json_decode($_POST['myData'], true);
$userid = $myData['userid'];
$sql = "SELECT * FROM 'usuario' WHERE id_usuario = '$userid'";
$user = $conn->query($sql) or die("[Protocolo] = #8");
$rowarray = array();
$rows = array();
while($linha = $user->fetch_assoc()) {
$row['id_usuario'] = $linha['id_usuario'];
$row['user_nome'] = $linha['user_nome'];
$row['user_cpf'] = $linha['user_cpf'];
$row['user_cnh'] = $linha['user_cnh'];
$row['user_rg'] = $linha['user_rg'];
$row['user_address'] = $linha['user_address'];
$row['user_bairro'] = $linha['user_bairro'];
$row['user_contato'] = $linha['user_contato'];
$row['user_dt_nascimento'] = $linha['user_dt_nascimento'];
$row['id_cidade'] = $linha['id_cidade'];
$row['user_nv_acesso'] = $linha['user_nv_acesso'];
array_push($rows, $row);
}
$dados['userupdate'] = $rows;
array_push($rowarray, $dados);
echo json_encode($rowarray);
$conn->close();
?>
When I see the POST DATA in AngularJS returns
200 - [object Object]
But when I duplicate the echo this way:
echo json_encode ($ rowarray); echo json_encode ($ data);
The Result on the console goes like this:
200 - "user_cdf": "user_cd": "user_cd": "user_cd": "user_cd": "user_cd" ":"Street 66, Quadra K49, Lot "User_contact": "user_contact": "6294131510", "user_dt_message": "1996-02-05", "id_city": "150140", "user_nv_acesso": "1"}] } "user_cpf": "1234", "user_cnh": "1234", "user_rg": "1234", "user_name" user_address ":" Street 66, Quadra K49, Lot "User_contact": "user_contact": "6294131510", "user_dt_message": "1996-02-05", "id_city": "150140", "user_nv_acesso": "1"}] }
Consulting 2 times, whoever can help is grateful.
Edit: