Home  >  Article  >  Backend Development  >  mysql控制台安插汉字无乱码,php插入就乱码

mysql控制台安插汉字无乱码,php插入就乱码

WBOY
WBOYOriginal
2016-06-13 11:58:50946browse

mysql控制台插入汉字无乱码,php插入就乱码;
header("content-type:text/html;charset=utf-8");
$title   =$_POST['f_title'];
$content =$_POST['f_content'];
//连接数据库
$link=mysql_connect('localhost','root','');
//选择数据库
mysql_select_db('bbs',$link);
//设置字符集
mysql_query("set names utf8");
//生成sql语句
$sql="insert into bss_info (title,content,add_time) values ('$title','$content',now())";
//执行sql语句
$rs=mysql_query($sql);
//生成sql错误提示
echo mysql_error();
//页面信息提示
if($rs)
{
echo "信息添加成功!";
}else 
{
echo "信息添加失败!";
}
?>
------解决方案--------------------
1、表是utf8编码吗
2、文件编码是utf-8编码吗

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