2
I have a code that sends data via cURL
to another page inside the server, only I have a problem... When sending this data to the other page, it inserts it into Mysql only when seeing the record inserted in Mysql all words after any accent is empty. For example, if I send Programming in Mysql only inserts Program the rest does not send.
Curl.php
<?php
header('Content-Type: application/json; charset=utf-8');
$ch = curl_init();
extract($_POST); //Recebe do $.post() do jQuery
$data = array('dados'=>array('nome'=>$nome, 'tipo'=>$tipo));
curl_setopt($ch, CURLOPT_URL, "http://localhost/app2/api/api.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$output = curl_exec($ch);
echo json_decode($output);
curl_close($ch);
?>
api.php
<?php
...
$dados = $_POST["dados"];
$nome = $dados["nome"];
$tipo = $dados["tipo"];
$insere = mysql_query("INSERT INTO tabela VALUES (NULL, '".$nome."', '".$tipo."')");
...
?>
[ Mandatory comment on deprecation of
mysql_*
and sql injection ]– brasofilo
But the
$_POST
arrives accentuated in theapi.php
? Or the problem ismysql_query
?– brasofilo
everything arrives accentuated correctly
– Alisson Acioli
Your base ta utf8 too ? and your connection is set to?
– Maria
So it’s not Curl problem, but Mysql problem.
– brasofilo
The problem is that I was with
utf8_decode($variavel)
before inserting into the seat, and doing so he would place an invalid character in the seat’s place and not insert correctly. Thank you all!– Alisson Acioli
Put this as a solution to your question, share your bread with others, rs @Alissonacioli
– Maria