1
hello! my database is in utf8 and on all pages I put the following code:
$con = mysqli_connect($_SG['servidor'], $_SG['usuario'], $_SG['senha'],$_SG['banco']);
mysqli_query($con,"SET NAMES 'utf8'");//converte tudo em utf-8 \/
mysqli_query($con,'SET character_set_connection=utf8');
mysqli_query($con,'SET character_set_client=utf8');
mysqli_query($con,'SET character_set_results=utf8');
And when it came time to store and display special characters, it was all working out. but overnight, without me having changed anything, it stopped working. When it comes to storing data by a form, it stores 'ã' as '£'. and if I store the data directly in the database it stores normally.
what do I do?? NOTE: the problem is in storing the character with accentuation and not in displaying.
added the healthy value in the'classi_atv_econ 'field. the hexadecimal value is as follows::
<?php
header('Content-Type: text/html; charset=UTF-8');
?>
<html>
<head>
<meta charset="utf-8">
<title>Cadastrar Empresa</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<?php
include("seguranca.php"); // Inclui o arquivo com o sistema de segurança
?>
</head>
<body>
<?php
include 'conexao.php';
$con = mysqli_connect($_SG['servidor'], $_SG['usuario'], $_SG['senha'],$_SG['banco']);
if (mysqli_connect_error()) {
printf('Erro de conexão: %s', mysqli_connect_error());
exit;
}
if (!mysqli_set_charset($con, 'utf8')) {
printf('Error ao usar utf8: %s', mysqli_error($con));
exit;
}
$nom_empre = $_POST['nom_empre'];
$inscri_muni = $_POST['inscri_muni'];
$situacao = $_POST['situacao'];
$cpf_cnpj_empre = $_POST['cpf_cnpj_empre'];
$consulta = "INSERT INTO empresa
(nom_empre,inscri_muni,situacao,cpf_cnpj_empre)VALUES ('$nom_empre','$inscri_muni','$situacao','$cpf_cnpj_empre')";
$cadastra = mysqli_query($con,$consulta);
if (!empty($cadastra){
header("location:home.php");
}
else {
echo "Não foi possível inserir os dados, tente novamente.";
// Exibe dados sobre o erro:
echo ("Dados sobre o erro:" . mysqli_error($con));
}
page code sending the form:
<?php
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
<title> Cadastrar </title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="style/style.css" rel="stylesheet">
<link href="style/login2.css" rel="stylesheet">
<?php
include("seguranca.php"); // Inclui o arquivo com o sistema de segurança
protegePagina(); // Chama a função que protege a página
admin();
expulsaUsuarioComum();
manutencao();
$con = mysqli_connect($_SG['servidor'], $_SG['usuario'], $_SG['senha'], $_SG['banco']);
if (mysqli_connect_error()) {
printf('Erro de conexão: %s', mysqli_connect_error());
exit;
}
if (!mysqli_set_charset($con, 'utf8')) {
printf('Error ao usar utf8: %s', mysqli_error($con));
exit;
}
?>
the rest of the code is normal html. just a form. do not move php in the rest of the code
This answer explains everything from header, connection, how to save files, and explains why characters like this
ã
appear http://answall.com/a/43205/3635– Guilherme Nascimento
The instructions are to both store and display, such a character is Unicode
ã
he is correct, UNICODE is UTF8, if you do step by step in the answer that Linkei will solve, the answer speaks not only of display, but of all that is necessary to use UTF8.– Guilherme Nascimento
vi. I did everything you asked, but the error continues. the problem is in storing the character. and not in displaying.
– Samuel Marlon
Your problem is double encoding. A given UTF-8 has been converted into UTF-8. To get an idea, just seeing your insertion code. Somewhere in the code has an improper encoding conversion.
– Bacco
I put a link to piratepad with the code compketo
– Samuel Marlon