听前辈说...

mysqlbaici 2012-09-04 12:33:40
听前辈说要在php页面加
header("Content-type: text/html; charset=utf-8");
这个,我加了还是乱码噢 ,
就这俩个php页面, 还有俩个页面是分页类来的。。

business_form.php
<?php
header("Content-type: text/html; charset=utf-8");
include 'comm.php';
if(isset($_POST['qq'])){
$qq = $_POST['qq'];
$selling_price = $_POST['selling_price'];
$original = $_POST['original'];
$expires = $_POST['expires'];


business_table.php


<?php
include 'paging.php';
$con =mysql_connect("localhost","root","123456");
mysql_select_db("business",$con);
$result = mysql_paging_query("SELECT * FROM business_table", 5);
echo "<table border='1' height='30' width='480' style=text-align:center>
<tr>
<th>QQ</th>
<th>价格</th>
<th>原价</th>
<th>到期时间</th><th>服务</th>
</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td width='120' height='30' >" . $row['qq'] . "</td>";
echo "<td width='120' height='30'>" . $row['selling_price'] . "</td>";
echo "<td width='120' height='30'>" . $row['original'] . "</td>";
echo "<td width='120' height='30'>" . $row['expires'] . "</td>";
echo "<td width='120' height='30'>" . $row['diamond']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_paging_bar();//显示分页条 下面也来一个
mysql_close($con);

?>
...全文
141 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
黄袍披身 2012-09-04
  • 打赏
  • 举报
回复
文件编码保存成utf-8格式
如果不确定是什么文件,那么每个文件你都加上 header("Content-type: text/html; charset=utf-8"); 当然图片类的就别加了
数据库链接来个1楼的 SET NAMES 'UTF8'

然后...

改一下昵称 2012-09-04
  • 打赏
  • 举报
回复
business_form.php 似乎只是处理表单提交,它并没有输出,因此 header("Content-type: text/html; charset=utf-8"); 向浏览器端声明编码是没有必要的。
倒是 business_table.php 要输出数据,所以有必要声明编码。

如果还有乱码的话,尝试 在每个 mysql_connect()后加一句代码
mysql_query("set names utf8"); 声明现在插入内容所使用的字符集,以及期望返回结果的字符集
sxabu 2012-09-04
  • 打赏
  • 举报
回复
好家伙,学习了,php有的学
黄袍披身 2012-09-04
  • 打赏
  • 举报
回复
business_table.php页面 缺少 SET NAMES 'UTF8' 语句
mysqlbaici 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

business_form.php 似乎只是处理表单提交,它并没有输出,因此 header("Content-type: text/html; charset=utf-8"); 向浏览器端声明编码是没有必要的。
倒是 business_table.php 要输出数据,所以有必要声明编码。

如果还有乱码的话,尝试 在每个 mysql_connect()后加一句代码
mysql_query……
[/Quote]

我还是帖我完整代码给你看下吧
business_form.php 代码
<?php
include 'comm.php';
if(isset($_POST['qq'])){
$qq = $_POST['qq'];
$selling_price = $_POST['selling_price'];
$original = $_POST['original'];
$expires = $_POST['expires'];
$diamond = $_POST['diamond'];
$conn = mysql_connect("localhost","root","123456");
mysql_query("set names utf8");
mysql_select_db("business");
$sql = "insert into business_table(qq,selling_price,original,expires,diamond)values('$qq','$selling_price','$original','$expires','$diamond')";
mysql_query($sql,$conn);
get_show_msg("business_table.php","订单成功");
}
?>
?>
<html>
<script type="text/javascript" >
function check(){
if(myform.qq.value==""){
alert("QQ");
return false;
}
if(myform.selling_price.value==""){
alert("sss");
return false;
}
if(myform.original.value==""){
alert("sss");
return false;
}
if(myform.expires.value==""){
alert("sss");
return false;
}
return true;
}
</script>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<title>title</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">

<form action="" method="POST" id="myform" name="myform" onsubmit="return check();">
QQ:
<input type="text" name="qq" id="qq" /><br/>
售价:
<input type="text" name="selling_price" id="selling_price" /><br/>
原价:
<input type="text" name="original" id="original" /><br/>
到期时间:
<input type="text" name="expires" id="expires" /><br/>
<input type="radio" name="diamond" value="真钻" />真钻
<input type="radio" name="diamond" value="好钻" />好钻
<input type="submit" name="submit" value="下单"/>
</form>

</body>
</html>

business_table.php 的

<?php
header("Content-type: text/html; charset=utf-8");
include 'paging.php';
$con =mysql_connect("localhost","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("business",$con);
$result = mysql_paging_query("SELECT * FROM business_table", 5);
echo "<table border='1' height='30' width='480' style=text-align:center>
<tr>
<th>QQ号</th>
<th>价格</th>
<th>原价</th>
<th>到期时间</th><th>服务</th>
</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td width='120' height='30' >" . $row['qq'] . "</td>";
echo "<td width='120' height='30'>" . $row['selling_price'] . "</td>";
echo "<td width='120' height='30'>" . $row['original'] . "</td>";
echo "<td width='120' height='30'>" . $row['expires'] . "</td>";
echo "<td width='120' height='30'>" . $row['diamond']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_paging_bar();//显示分页条 下面也来一个
mysql_close($con);

?>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧