2
I’m developing a web application with Extjs 4 and PHP. I’m having trouble doing the INSERT
in the database. For example, I registered the product "tea", but it saves "chu00e1". My entire database is in UTF-8, my PHP files are with header in UTF-8, my HTML too, I am saving my files in UTF-8, IE, everything is with the same encoding.
Below is the line of code where I do the INSERT
.
<?php
//chama o arquivo de conexão com o bd
include("connect.php");
$info = $_POST['data'];
$data = json_decode(stripslashes($info));
$codigo = $data->codigo;
$nome = $data->nome;
$descricao = $data->descricao;
$quantidade = $data->quantidade;
$sigla = $data->sigla;
$query = sprintf("INSERT INTO produtos (codigo, nome, descricao, quantidade, sigla) values ('%s', '%s', '%s', '%d', '%s')",
mysql_real_escape_string($codigo),
mysql_real_escape_string($nome),
mysql_real_escape_string($descricao),
mysql_real_escape_string($quantidade),
mysql_real_escape_string($sigla));
$rs = mysql_query($query);
echo json_encode(array(
"success" => mysql_errno() == 0,
"data" => array(
"id" => mysql_insert_id(),
"codigo" => $codigo,
"nome" => $nome,
"descricao" => $descricao,
"quantidade" => $quantidade,
"sigla" => $sigla
)
));
?>
Read the documentation: utf8_encode
– MarceloBoni
I had already looked there. I can’t use utf8_encode because it asks String as parameter and my data is in an array.
– Marcelo Augusto
This does not interfere with anything, Voce is storing a string inside the array :) :
$seuCampo= utf8_encode($data->seuCampo)
;– MarceloBoni
Actually it has to be like this:
$string = $data->seuCampo;
$suaStringCodificada = utf8_encode($string);
– MarceloBoni
It didn’t work out, man..
– Marcelo Augusto