我做了一个简单的留言板,为什么添加到数据库中的中文字符不能正常显示都是“????”之类的,数字和英文是可以正常显示的!

解决方案 »

  1.   

    在往数据库写如数据的时候先执行
    mysql_query('set names utf8');或者mysql_query('set names gb2312');
      

  2.   

    刚才的问题解决了。可是又有了一个问题
    这是留言板的预览的PHP 文件,可为什么预览的不了啊!
    <?php
    include("conn.php");
    ?>
    <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
    <?
    $sql="select * from message order by id desc";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query))
    {
    ?>
      <tr bgcolor="#eff3ff">
      <td>标题:<?=$row[title]?> 用户:<?=$row[user]?></td>
      </tr>
      <tr bgColor="#ffffff">
      <td>内容:<?=$row[content]?></td>
      </tr>
     <?
     }
     ?>
    </table>
      

  3.   

    $row['title']
    $row['user']
    $row['content']
      

  4.   

    晕怎么又是你同样的错误犯第二次?太不应该了!
    http://topic.csdn.net/u/20110507/00/2585c9ab-983c-4fb6-a10f-ebdba0fe9078.html
      

  5.   

    不是这个原因啊!
    我找到了源码就是这样的$row[title]
    $row[user]
    $row[content]
      

  6.   

    至少是原因之一吧,把php代码块开始标签<?改为<?php.
    <?=$row[title]; ?>改为<?php echo $row['title']; ?><?这是短标签的写法,需要在php.ini中修改配置short_open_tag = On才行。
      

  7.   


    Notice: Undefined variable: row in D:\software\PHP\htdocs\list.php on line 12
    这个我已经改过了short_open_tag = On。
      

  8.   

    把你修改后的代码贴出来,这个提示的意思是$row变量未定义。
      

  9.   

    <?php
    include("conn.php");
    ?>
    <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
    <?
    $sql="select * from message order by id desc";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query))
    {
    ?>
      <tr bgcolor="#eff3ff">
      <td>标题:<?php echo $row['title']; ?>
     用户:<?php echo $row['user']; ?></td>
      </tr>
      <tr bgColor="#ffffff">
      <td>内容:<?php echo $row['content']; ?></td>
      </tr>
     <?
     }
     ?>
    </table>
      

  10.   

    看sql执行语句是否输出值,之后看循环是否有值,一步步的看看
      

  11.   

    <?php
    include("conn.php");
    ?>
    <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
    <?php
    $sql="select * from message order by id desc";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query))
    {
    ?>
      <tr bgcolor="#eff3ff">
      <td>标题:<?php echo $row['title']; ?>
     用户:<?php echo $row['user']; ?></td>
      </tr>
      <tr bgColor="#ffffff">
      <td>内容:<?php echo $row['content']; ?></td>
      </tr>
     <?php
     }
     ?>
    </table>世界上怕就怕认真二字