Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Manoel Vitor

Problemas com acentos.

Recommended Posts

Boa tarde pessoal.

Estou tentando um novo cadastro mas percebi que os acentos e ç não saem corretos no bd.

mesmo sendo utf8 a minha tabela e no inicio dos codigos colocando <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

se eu cadastro "ação" no banco de dados fica "ação"

utilizo o wampserver com phpadmin para criar as tabelas

meu arquivo de conexão é este abaixo.

 

<?php

# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_locar = "localhost";
$database_locar = "locar";
$username_locar = "root";
$password_locar = "";
$locar = @mysql_pconnect($hostname_locar, $username_locar, $password_locar) or trigger_error(mysql_error(),E_USER_ERROR);
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

veja o meu codigo

 

<?php require_once('../../xampp/htdocs/locar/Connections/locar.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tb_controle (teste) VALUES (%s)",
GetSQLValueString($_POST['teste'], "text"));
mysql_select_db($database_locar, $locar);
$Result1 = mysql_query($insertSQL, $locar) or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form accept-charset="utf-8" id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<label for="teste"></label>
<input type="text" name="teste" id="teste" />
<input type="submit" name="button" id="button" value="Submit" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Neste trecho aqui, que esta bem no final, você utiliza o utf8_encode():

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tb_controle (teste) VALUES (%s)",
                       GetSQLValueString($_POST['teste'], "text"));

Vai ficar assim, repare a última linha:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tb_controle (teste) VALUES (%s)",
                       GetSQLValueString(utf8_encode($_POST['teste']), "text"));

Eu apliquei a função no $_POST vindo do formulário

Compartilhar este post


Link para o post
Compartilhar em outros sites

Após:

$locar = @mysql_pconnect($hostname_locar, $username_locar, $password_locar) or trigger_error(mysql_error(),E_USER_ERROR);

Coloque:

mysql_query("SET NAMES 'utf8'");

Isto só irá afetar os novos registros...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom dia Pessoal consegui resolver.

Estava em utf8 dai mudei meu codigo para <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> e funcionou.

Vlw pela atenção.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.