我的数据库配置文件是用gb2312的,还有网页上的字符集也是这个;为什么连接到数据库还会出现乱码?
<!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 if(!isset($_POST["button"])){?>
<form id="form1" name="form1" method="post" action="">
<table width="323" height="210" border="1" bgcolor="#FFFF66">
<tr>
<td width="88"><div align="left">用户名:</div></td>
<td width="219"><div align="left">
<label>
<input type="text" name="username" id="textfield" />
</label>
</div></td>
</tr>
<tr>
<td><div align="left">密码:</div></td>
<td><div align="left">
<label>
<input type="password" name="pwd" id="textfield2" />
</label>
</div></td>
</tr>
<tr>
<td><div align="left">重复密码:</div></td>
<td><div align="left">
<input type="password" name="textfield3" id="textfield3" />
</div>
<label></label></td>
</tr>
<tr>
<td><div align="left">姓名:</div></td>
<td><div align="left">
<label>
<input type="text" name="name" id="textfield4" />
</label>
</div></td>
</tr>
<tr>
<td><div align="left">E-Mail:</div></td>
<td><div align="left">
<label>
<input type="text" name="email" id="textfield5" />
</label>
</div></td>
</tr>
<tr>
<td colspan="2"> <label>
<input type="submit" name="button" id="button" value="提交" />
<input type="reset" name="button2" id="button2" value="重置" />
</label></td>
</tr>
</table>
</form>
<?php }else{
date_default_timezone_set(Shanghai);
$filename=basename($_SERVER["SCRIPT_FILENAME"]);
$username=$_POST["username"];
$pwd=$_POST["pwd"];
$name=$_POST["name"];
$email=$_POST["email"];
$lasttime=$_POST[date("Y-m-d",fileatime($filename))];
echo $lasttime;
$db = @new mysqli("localhost", "root", "123456"); //调用mysqli的构造函数建立连接, $db为对象型变量
If (mysqli_connect_errno()) //检查连接是否成功,mysqli_connect_errno()函数返回连接失败的错误编号。
{
echo "连接数据库失败!";
}
$db-> select_db("test");
$sql = "SELECT * FROM t_user WHERe f_username='$username'";
$rs = $db->query($sql);
if ($rs && $rs->num_rows > 0) // num_rows的值为执行查询后受影响的行数。
{
echo "用户名已存在!";
}
$sql = "INSERT INTO t_user (f_username,f_password,f_name,f_email,f_lasttime) VALUES";
$sql .= "('$username','$pwd','$name','$email','$lasttime')";
$rs = $db->query($sql);
if (!$rs){
echo "添加记录失败!";
}
else {
echo "添加记录成功!";
}
$db->close();
echo "$username";
}?>
</body>
</html>