+ -
当前位置:首页 → 问答吧 → wamp+PHP问题

wamp+PHP问题

时间:2011-11-26

来源:互联网

一个简单的留言功能,为啥在网页上输入中文,在数据库了就变乱码,求助!!!!!

这是页面和链接数据库代码:

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<?php 
include ('conn.php');
if($_POST['sub']){
$ghj="insert into message (id,user,title,content,lastdate) ".
"value('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($ghj);
echo "成功";
}

?>
<form action="index.php" method="post">
用户:<input type="text" size="10" name="user"/><br>
标题:<input type="text" name="title"/><br/>
内容:<textarea name="content"></textarea><br/>
<input type="submit" name="sub" value="发布留言"/>

</form>

</head>


这是conn.php文件代码:
<?php
$conn = @ mysql_connect("localhost", "root", "") ;
mysql_select_db("new", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
?>

作者: zqkyle_2011   发布时间: 2011-11-26

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
mysql_query("set names 'GBK'");

您觉得合适吗?

作者: xuzuning   发布时间: 2011-11-26

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
mysql_query("set names 'GBK'"); //使用GBK中文编码;
页面编码与数据库编码要一致吧。

作者: lusizeng   发布时间: 2011-11-26

把<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
换成<meta http-equiv="Content-Type" content="text/html; charset=GBK" />吗?

作者: zqkyle_2011   发布时间: 2011-11-26

相关阅读 更多