php连接数据库

dong_snow 2011-05-07 11:26:28
我做了一个简单的留言板,为什么添加到数据库中的中文字符不能正常显示都是“????”之类的,数字和英文是可以正常显示的!
...全文
116 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
码无边 2011-05-07
  • 打赏
  • 举报
回复
看sql执行语句是否输出值,之后看循环是否有值,一步步的看看
dong_snow 2011-05-07
  • 打赏
  • 举报
回复
<?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>
乌镇程序员 2011-05-07
  • 打赏
  • 举报
回复
把你修改后的代码贴出来,这个提示的意思是$row变量未定义。
dong_snow 2011-05-07
  • 打赏
  • 举报
回复

Notice: Undefined variable: row in D:\software\PHP\htdocs\list.php on line 12
这个我已经改过了short_open_tag = On。
乌镇程序员 2011-05-07
  • 打赏
  • 举报
回复
至少是原因之一吧,把php代码块开始标签<?改为<?php.
<?=$row[title]; ?>改为<?php echo $row['title']; ?>

<?这是短标签的写法,需要在php.ini中修改配置short_open_tag = On才行。
dong_snow 2011-05-07
  • 打赏
  • 举报
回复
不是这个原因啊!
我找到了源码就是这样的$row[title]
$row[user]
$row[content]
乌镇程序员 2011-05-07
  • 打赏
  • 举报
回复
晕。。。怎么又是你。。。同样的错误犯第二次?太不应该了!
http://topic.csdn.net/u/20110507/00/2585c9ab-983c-4fb6-a10f-ebdba0fe9078.html
乌镇程序员 2011-05-07
  • 打赏
  • 举报
回复
$row['title']
$row['user']
$row['content']
dong_snow 2011-05-07
  • 打赏
  • 举报
回复
刚才的问题解决了。可是又有了一个问题
这是留言板的预览的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>
wwww3g 2011-05-07
  • 打赏
  • 举报
回复
在往数据库写如数据的时候先执行
mysql_query('set names utf8');或者mysql_query('set names gb2312');
dong_snow 2011-05-07
  • 打赏
  • 举报
回复
世界上怕就怕认真二字
xuzuning 2011-05-07
  • 打赏
  • 举报
回复
<?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>

世界上怕就怕认真二字

21,890

社区成员

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

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