请帮忙修改《电脑报》11月12日中介绍的一个简单的PHP聊天室

munn 2001-11-16 09:02:32
以下是《电脑报》11月12日中介绍的一个很简单的PHP聊天室
里面有几处很显眼的错误我已改,但是还不能显示聊天记录。
请大侠修改。

<!-- 文件index.htm -->
<html>
<head>
<title>我的聊天室</title>
</head>
<frameset rows="*,80" frameborder="no" border="0" framespacing="0">
<frame name="list" scrolling="auto" src="display.php" >
<frame name="post" scrolling="no" src="write.php">
</frameset>
<noframes>
<body>
</body>
</html>


<!-- 文件display.php -->
<html>
<meta http-equiv="refresh" content="5;url=
<?php echo "$php_self"; ?>
">

<body>
<?php
echo "<center><font size='5'>欢迎光临我的聊天室</font>";
mysql_connect("localhost","root","0628");
$sql = "select username,text from talk order by date desc limit 0,20";
$result = mysql_db_query("my_test_chat",$sql);

if ($result)//估计是以下的地方有问题.很简单,希望大侠们帮着改一下.
{
while ($r = mysql_fetch_array($result))
{ //取出结果
$username = $r["username"]; //使php变量username可使用表中username
$text = $r["text"];
echo "<tr>";
echo "<td align='left'><font size='1'>$username说道:$text</font></td>";
echo "</tr>";
}
}
else
{
echo "对不起,系统故障!";
}

mysql_free_result($result); //断开连接
?>
</body>
</html>


<!-- 文件write.php -->
<?php
if (($username != "") and ($text != ""))
{
$connect = mysql_connect("localhost","root","0628"); //连接MySQL数据库
$sql = "insert into talk (username,date,text) values ('$username','$date','$text')"; //插入语句
$result = mysql_db_query("my_test_chat",$sql); //插入执行
}
?>


<html>
<head>
<title>用户输入</title>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form method="POST" action="write.php"><p>
你的ID:<input type=text name=userid size=12>
发言:<input type=text name=text size=51>
<input type=submit value='提交'></p>
</form>
</body>
</html>



SQL
(DBNAME:my_test_chat)
create table talk
( userid int(5) not null auto_increment,
username varchar(20) not null,
date varchar(8) not null,
text varchar(50) not null,
primary key (userid)
);
...全文
71 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
munn 2001-11-20
  • 打赏
  • 举报
回复
我原来代码底下不就是你写的吗?
不行!
munn 2001-11-20
  • 打赏
  • 举报
回复
我要知道还问你!
hbolive 2001-11-20
  • 打赏
  • 举报
回复
给出错误提示,大家好帮忙修改嘛~!
munn 2001-11-19
  • 打赏
  • 举报
回复
我试一下,如果可以一定给分.
谢谢
SCHBOY 2001-11-19
  • 打赏
  • 举报
回复
while ($r = mysql_fetch_array($result))
{ //取出结果
$username = $r["username"]; //使php变量username可使用表中username
$text = $r["text"];
echo "<tr>";
应改为
echo "<td align='left'><font size='1'>".$username."说道:".$text."</font></td>";
echo "</tr>";
}
你可试试
munn 2001-11-18
  • 打赏
  • 举报
回复
斑竹帮忙!
munn 2001-11-17
  • 打赏
  • 举报
回复
怎么还是没人来改???
而且看的人也这么少????
php版真的人气就这么差???
斑竹帮帮忙。
我想知道错在哪里!

21,881

社区成员

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

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