Home > Backend Development > PHP Tutorial > php输出乱码有关问题

php输出乱码有关问题

WBOY
Release: 2016-06-13 10:06:36
Original
845 people have browsed it

php输出乱码问题
只是调用了下数据库,竟然就出现乱码了!!!

程序如下

$q=$_GET["q"];


$con = mysql_connect("localhost","root","198600");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_query("set names 'gb2312'"); 
mysql_select_db("my_db", $con);

$sql = "SELECT * FROM persons WHERE nick='$q'";
$query = mysql_query($sql);
 $rows=mysql_num_rows($query);
 if($rows)
{
  echo '用户名已被注册';
}
 else
{
  echo '用户名可用';
}
mysql_close($con);

?>


网页编码是gb2312
数据库编码是utf8

想不通的问题是,只是调用了下数据库,又没从数据库写入和输出,为啥页面输出会是乱码呢,求解!!

------解决方案--------------------
在头部加上header('Content-Type:text/html;charset=gb2312');

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template