昨天查了许久 所有页面统一UTF-8 数据库也是UTF-8-unicode-ci 结果还是乱码
然后尝试GB2312 也不行。。
我发代码给大家 看看 新手 什么都不懂。
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title><body><form action="test.php" method="post">姓:<input type="text" name="firstname" />
名:<input type="text" name="lastname" />
年龄:<input type="text" name="age"/>
<input type="submit" /></form>
</body>
</html>
PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<?php
header("Content-type: text/html;charset=gb2312");
$con=mysql_connect("localhost","asd","asd123");
if(!$con){
die("connot connect: ".mysql_error());}
mysql_select_db("my_db",$con);
$sql="INSERT INTO person(FirstName,LastName,Age)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
mysql_query($sql,$con);
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
</body>
</html>
然后尝试GB2312 也不行。。
我发代码给大家 看看 新手 什么都不懂。
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title><body><form action="test.php" method="post">姓:<input type="text" name="firstname" />
名:<input type="text" name="lastname" />
年龄:<input type="text" name="age"/>
<input type="submit" /></form>
</body>
</html>
PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<?php
header("Content-type: text/html;charset=gb2312");
$con=mysql_connect("localhost","asd","asd123");
if(!$con){
die("connot connect: ".mysql_error());}
mysql_select_db("my_db",$con);
$sql="INSERT INTO person(FirstName,LastName,Age)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
mysql_query($sql,$con);
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
</body>
</html>
这里 写的是gb2312? 怎么不写utf-8呀
mysql_select_db("my_db",$con);
mysql_query("SET NAMES 'UTF8'");
mysqli_query("set names utf8", $conn);