Home >Backend Development >PHP Tutorial > php中文乱码解决办法
php中文乱码
一个简单的数据库插入界面和后台
add.html
<script><br />
function onAddItem()<br />
{<br />
var xmlhttp;<br />
var workcontent = $("#tb_content").attr("value");<br />
var contact = $("#tb_contact").attr("value");<br />
var remark = $("#tb_remark").attr("value");<br />
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari<br />
xmlhttp=new XMLHttpRequest();<br />
}else{// code for IE6, IE5<br />
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");<br />
}<br />
xmlhttp.onreadystatechange=function()<br />
{<br />
if (xmlhttp.readyState==4 && xmlhttp.status==200){<br />
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;<br />
}<br />
}<br />
var requestStr = "add.php?content="+workcontent + "&contact="+contact +"&remark="+remark;<br />
xmlhttp.open("GET",requestStr,true);<br />
xmlhttp.send();<br />
alert(requestStr);<br />
}<br />
<br />
</script>
后台 add.php
$workcontent = $_REQUEST["workcontent"];
$contact = $_REQUEST["contact"];
$remark = $_REQUEST['remark'];
include 'conn.php';
$sql = "insert into WorkContentTable(workcontent,contact,remark) values('$workcontent','$contact','$remark')";
$issuccess = @mysql_query($sql);
if(!issuccess){
echo "添加不成功!";
}else{
$str = "添加了一条数据,业务内容为:" + $workcontent + ",联系人为:" + $contact + ",备注为:" + $remark;
echo $str;
}
?>
mysql的编码为默认的utf-8
在firefox浏览器中操作,mysql为中文正常显示
在IE中操作,mysl中文乱码
add.php?workcontent=测试&contact=test&remark=ss
firefox和ie均echo出乱码
本人php新手 这个中文乱码问题搞的真纠结
网上找的方法都试过了 没用 iconv函数转码之后为空串