3
I got an SQL script that "mounts" 3 tables, one with country, one with states and one with Brazilian cities.
The script makes the collection
, of the names, in latin1_swedish_ci
and I needed it to be utf8_bin
, because names with accent generates another character, and I still have to put these names in format json
.
My HTML:
<div align="center">
<form>
<input type="hidden" ng-model="estado.idEstado">
Estado <input type="text" ng-model="estado.nome">
Sala <input type="text" ng-model="estado.sala">
<button ng-click="atualizarEstado(estado)">Atualizar</button><br>
</form>
My php:
<?php
include_once("conPDO.php");
$pdo = conectar();
$id = $_GET['idEstado'];
$buscarEstado=$pdo->prepare("SELECT * FROM estado WHERE idEstado=:id ");
$buscarEstado->bindValue(":id", $id);
$buscarEstado->execute();
//header('Content-Type: application/json');
$return = array();
while ($linha=$buscarEstado->fetch(PDO::FETCH_ASSOC)) {
$return = $linha;
print_r($return);
}
echo json_encode($return);
?>
On the console appears this:
Array
(
[idEstado] => 4
[nome] => Amap�
[uf] => AP
[pais] => 1
[sala] =>
)
Test do the following
$return = utf8_encode($linha);
andjson_encode($return JSON_UNESCAPED_UNICODE);
. See if it solves.– MoisesGama
This message appeared on the console: "<b>Warning</b>: utf8_encode() expects Parameter 1 to be string, array Given in <b>/Applications/MAMP/htdocs/systems/systems_web/Vigilantescomunitarios/admin/php/pegaEstado.php</b> on line <b>22</b><br />"
– GustavoSevero
Then just try
echo json_encode($return JSON_UNESCAPED_UNICODE);
Leave Return as it was.– MoisesGama
Nothing... Shows this error on the console: "GET http://localhost:8888/systems/systems_web/Vigilantescomunitarios/admin/php/pegaEstado.php? idEstado=4 500 (Internal Server Error)"
– GustavoSevero
All right, test that
echo json_encode($return, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
with this he will try to do all the decodes he has.– MoisesGama
Thanks for your attention @Moisesgama, but I already did. I did this: $line['name'] = mb_convert_encoding($line['name'], "ISO-8859-1");
– GustavoSevero
Gave another problem... The name, now, is displayed, in the listing, this way Amapã¡ instead of Amapá. And if I try to edit to correct, it no longer appears in the edit field.
– GustavoSevero
@Moisesgama, I did this: $line['name'] = json_encode($line, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE); array_push($line, $line['name']); $Return = $line; And this appeared on the console: "Array ( [idEstate] => 4 [name] => [Uf] => AP [parents] => 1 [room] => Eama4 [0] => ) {"idState":"4","name"false,"Uf"""AP","parents":"1","room":"Ea4","room","}"
– GustavoSevero
put this before the include
header("Content-type: text/html;charset=utf-8");
and see how it prints onprint_r($return);
without putting in theJSON
– MoisesGama
Before doing what you suggested to me, I did it in a way that is working, HOWEVER, when I update the data, the name comes "broken" hehehe ?
– GustavoSevero