Home >Backend Development >PHP Tutorial >php中文写入access数据库乱码问题

php中文写入access数据库乱码问题

WBOY
WBOYOriginal
2016-06-23 14:19:031168browse

用的ajax;
前台编码utf-8,用jquery的post传到后台,写入数据库后中文乱码,请问应该怎么设置编码或者转码。

$(document).ready(function(){   $("#usersubmit").click(function(){           $.post("addsinger.php", {                        singername : $("#singername").val() ,                        area : $("#area").val() ,  					sex : $("#sex").val() , 				    singerimg : $("#singerimg").val() ,    					singercid : $("#singercid").val() ,   					singerfirstword : $("#singerfirstword").val()                    }, function (data, textStatus){            if(data=="success"){						window.location.reload()						}                }           );      })  });

$singername=$_POST['singername'];$area=$_POST['area'];$sex=$_POST['sex'];$singercid=$_POST['singercid'];$singerimg=$_POST['singerimg'];$singerfirstword=$_POST['singerfirstword'];$connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath("../mtv.mdb");$conn=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC );$sql = "INSERT INTO singer (singer,singerarea,singersex,singercid,singerimg,singerfirstword) VALUES ('$singername','$area','$sex','$singercid','$singerimg','$singerfirstword')";$rs=odbc_do($conn,$sql);echo "success";


还有一个,后台怎么确定这一条记录成功是否被写入,然后返回一个布尔值。


回复讨论(解决方案)

表是什么编码?

addsinger.php   文件的编码格式 和数据库的编码格式。请确定

ajax 总是以 utf-8 发送数据
access 只有 gbk 和 unicode 两种编码

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn