Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera,
Estou utilizando ASP com conexão ao MySql.
Quando utilizo o comando insert ele insere os dados, mas vem como caracteres diferentes do esperado.
Exemplo: Mário = Mário
No select funciona normal, mas no insert é que ocorre esse problema. Segue os códigos:
conn.asp
<%
dim objcon, objrs
set objcon = server.createobject ("adodb.connection")
objcon.open "driver=MySQL ODBC 5.1 driver; server=localhost; uid=root; pwd=;database=db_brino; charset=utf8; option=3;"
%>
pedido.asp
<%@ codepage="1252" language="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/estilo.css" type="text/css" />
<title>Pedido</title>
</head>
<body><form name="pedido" method="post" action="pedido.asp">
<p><b>Nome:</b></p>
<p><input type="text" size="50" name= "txtnome"/></p>
<p><b>Endereço:</b></p>
<p><input type="text" size="50" name= "txtend"/></p>
<p><b>Telefone:</b></p>
<p><input type="text" size="5" maxlength="8" name= "txttel"/></p>
<p><br><br></p>
<p><input type="submit" value=" Pedido "/></p>
</body>
</html><%@ codepage="1252" language="VBScript" %>
Coloquei logo no início mas não mudou nada, continua gravando os dados da mesma forma. Veja o primeiro post como ficou.
coloca assim:
Mudar o head da página que solicita os dados para que ele fique assim
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Na página que responde os dados colocar isso antes do retorno co conteúdo (logo no topo):
<%
Response.AddHeader "Content-Type", "text/html; charset=utf-8"
Response.AddHeader "Pragma", "no-cache"
response.Charset="utf-8"
%>
Cara, não funcionou ainda...
Então vou postar a forma como criei a base de dados e tabela.
Base de dados e a tabela:
CREATE DATABASE db_brino DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE TABLE `db_brino`.`pedi` (
`cod_ped` INTEGER UNSIGNED AUTO_INCREMENT,
`nome_cli` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`end_cli` VARCHAR(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tel_cli` VARCHAR(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`cpf_cli` VARCHAR(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`cod_ped`)
)
ENGINE = InnoDB
CHARACTER SET utf8 COLLATE utf8_general_ci;
<%@ codepage="1252" language="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/estilo.css" type="text/css" />
<title>Pedido</title>
</head>
<body>
<form name="pedido" method="post" action="pedido.asp">
<p><b>Nome:</b></p>
<p><input type="text" size="50" name= "txtnome"/></p>
<p><b>Endereço:</b></p>
<p><input type="text" size="50" name= "txtend"/></p>
<p><b>Telefone:</b></p>
<p><input type="text" size="5" maxlength="8" name= "txttel"/></p>
<p><br><br></p>
<p><input type="submit" value=" Pedido "/></p>
</body>
</html>
O que fiz foi o seguinte:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<%
Response.AddHeader "Content-Type", "text/html; charset=utf-8"
Response.AddHeader "Pragma", "no-cache"
response.Charset="utf-8"
%>
<%If (Request.ServerVariables("REQUEST_METHOD") = "POST") then
SET rs = objcon.Execute("INSERT INTO pedido (nome_cli, end_cli, tel_cli, cpf_cli)
VALUES ('"&request.form("txtnome")&"', '"&request.form("txtend")&"', '"&request.form("txttel")&"', '"&request.form("txtcpf")&"')")
Response.Redirect "escolha.asp"
End If
%>
</body>
</html>
Fiz uma nova página em que recebe os dados e grava no banco
usa assim no topo da página
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt" xml:lang="pt">
<head>
<title>Título</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
...Resolvido,
Funcionou xD
Obrigado aos dois!
olha este link