出现问题后,我按网上的说法
在index.php(提交表单的页面)前面加了<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
在page-1.php(要获取的页面)
加了  header("Content-Type:text/html;charset=GB2312");
  $key=$_POST['key']=iconv("UTF-8","gb2312",$_POST["key"]);  
结果还是不行。我是菜鸟咯,随便发表意见,反正把问题解决就行!

解决方案 »

  1.   

    index.php 首行加上
    header("Content-Type:text/html;charset=GB2312");另外,把php文件也设置为gbk编码
      

  2.   

    弱弱问下,header("Content-Type:text/html;charset=GB2312");
     和这个"<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />”
      

  3.   

    header() 函数向客户端发送原始的 HTTP 报头。
    <meta> 元素可提供有关页面的元信息关于meta的介绍,我一下说不清楚,看下面的介绍吧
    http://www.w3school.com.cn/tags/tag_meta.asp
      

  4.   

    在index.php(提交表单的页面)前面加了<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
    如果这个 meta 生效的话,提交的表单就是 GB2312 编码的了
    所以 在page-1.php(要获取的页面)
      $key=$_POST['key']=iconv("UTF-8","gb2312",$_POST["key"]);

    是错误的!
    你这是把 GB2312 当做 UTF-8 处理,怎么能得到正确的结果呢?  header("Content-Type:text/html;charset=GB2312");
    位于 http 协议头中,其优先级高于
    <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
      

  5.   

    既然index.php编码的方式为gb2312,就将page-1.php的编码前加上header("Content-Type:text/html;charset=GB2312");
    可我这么一改,还是一样,对于这方面感觉太吃力了。
      

  6.   


    就是说$_post获得的变量数据仍旧是乱码(我单独输出了的)
    版主,别介意呀,你可以随便说我的,但自己别生气咯,身体是自己的。本来计算机的,都是在花费着生命力。
      

  7.   

    贴出表单页 html 源代码
      

  8.   

    <html>
    <body>
    <?php
    header("Content-Type:text/html;charset=GB2312");
    $link=mysql_connect("localhost","root","qidian110");
    $key=$_POST['key'];
    mysql_select_db("books",$link);
    $query="SELECT * FROM book WHERE title='$key' or type='$key' or author='$key'";
    $result=mysql_query($query);
    echo "$key";
    echo "<table border='1'>
    <tr>
    <th>编号</th>
    <th>书名</th>
    <th>语言</th>
    <th>作者</th>
    <th>剩余数量</th>
    </tr>";while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>".$row['b_id']."</td>";
      echo "<td>".$row['title']."</td>";
      echo "<td>".$row['type']."</td>";
      echo "<td>".$row['author']."</td>";
          echo "<td>".$row['number']."</td>";
      }
    ?>
    </body>
    </html>
      

  9.   

    上面的是page-1.php。
    下面是index.php
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
    <style type="text/css">
    div#container{margin:0 auto;width:100%;}
    div#header {background-color:#FFF;height:100px;margin-bottom:5px}
    div#maincontent{height:500px; margin-bottom:5px;} 
    #sidebar { float:left; width:200px; height:500px; background:#3F9;}
    #content { margin-left:205px !important; margin-left:202px; height:500px; background:#FF9;}
    </style>
    </head><body>
    <form method="post" action="page-1.php">
    <div id="container"><div id="header" align="center">
    <br/>
    <h1> 
    <br/>图书馆索引系统</h1>
    </div><div id="maincontent">
      <div id="sidebar">
      <br/>
      <br/>
      <br/>
      <br/>
      <p>&nbsp;用户名:</p>
      &nbsp; 
      <input type="text" name="use" />
      <br/>
      <br/>
      <br/>
      <p>&nbsp;密码:</p>
      &nbsp; 
      <input type="password" name="pass" />
      <br/>
      <br/>         
       &nbsp; 
       &nbsp; 
       &nbsp; 
       &nbsp; 
       &nbsp; 
       &nbsp; 
       <input type="submit"  value="登陆">
      </div>
      <div id="content" align="center">
      <h2>搜索</h2>
      <br/>
     <input type="text" name="key" /> <input type="submit"  value="搜一搜"> </div>
    </div>
    </div></form>
    </body>
    </html>
      

  10.   

    page-1.php 中在 header("Content-Type:text/html;charset=GB2312"); 下面加上
    print_r($_POST);  贴出结果
      

  11.   

    Array ( [use] => [pass] => [key] => ���տƼ� )
      

  12.   

    apache+php+mysql
    用的ie 9 以及百度浏览器
      

  13.   

    麻烦大家了,昨天终于把这个问题解决了,编码方式我全部改成了"UTF-8",(因为mysql建表时,就是UTF-8).麻烦各位。我以后也定会注意每个页面的编码方式。
      

  14.   

    解决就好,知其然也要知其所以然,自己总结一下吧其实每次传输过程都要考虑前后的编码问题,别忘了,编辑器打开php文件写代码也是一次传输过程,保存是另一次,按这样的思路,自己列出每一个传输过程再检查问题就变简单了,
      

  15.   

    统一编码就好,用个好的编辑器也很重要,推荐notepad++,想改编码,非常方便。