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 to storing and displaying special characters it was working fine. but from one day to the next, without me having changed anything, it stopped working. when storing data on a form, it stores 'a' as 'a'. and if I store the data directly in the database it stores normally.
What do I do ?? NOTE: The problem is to store the character with accent and not display.
I added the value 'sã' in the 'classi_atv_econ' field. the hexadecimal value is as follows:
<?phpheader('Content-Type:text/html;charset=UTF-8');?><html><head><metacharset="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 that sends 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. only one form. I do not mess with php in the rest of the code