php mysql乱码

来源:百度知道 编辑:UC知道 时间:2024/05/12 17:58:13
$usernc=$_POST[usernc];
$userpwd=$_POST[userpwd];
$userpwd1=$_POST[userpwd1];
$email=$_POST[email];
$qq=$_POST[qq];
$truename=$_POST[truename];
$address=$_POST[address];
$city=$_POST[city];
$state=$_POST[state];
$zipCode=$_POST[zipCode];
$country=$_POST[country];
$ref=$_POST[ref];
$paymentAccount=$_POST[paymentAccount];
$xym=$_POST[xym];
if (MySQL_query("insert into tb_user (
email,qq,truename,address,city,state,zipcode,country,ref,PaymentAccount,userpwd,usernc,id,regtime,lastlogintime,logintimes )
values ('$email', '$qq', '$truename','$address', '$city', '$state', '$zipcode', '$country', '$ref', '$PaymentAccount', '$userpwd', '$usernc', NULL ,'1', '$time', '$time')",$conn)){
MySQL_query("set names gb2312");

插入数据库正确

网页和数据库都是GB2312了,还差一个:每次连接后设置为GB2312,方法是:
mysql_connetc(...);
mysql_query('set names gb2312');

三个地方编码统一就不会是乱码,可以都是GB2312,也可以都是UTF-8,关键是三统一。

在执行任何
mysql_query(......);
操作之前
先执行
mysql_query("set names gbk");
你的是数据库编码问题

更详细的解释请参加我的博客
http://hi.baidu.com/coyeah/

MySQL_query("insert into tb_user (
在这个query之前执行

mysql_query("set names gbk");
这句话的意思告诉mysql,之后的sql语句是gbk编码的.

$hostname_buffett = "localhost:3306";
$database_buffett = "aa";
$username_buffett = "root";
$password_buffett = "123456";
$aa = mysql_pconnect($hostname_aa, $username_aa, $password_aa) or trigger_error(mysql_error(),E_USER_ERROR);

把这一句“mysql_query("set names 'gb2312'");”加到上面的最后一行及可以了,也就是连接数据库命令的后面,其他PHP页面的编码也要用GB231