免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 Perl help
最近访问板块 发新帖
查看: 1070 | 回复: 0
打印 上一主题 下一主题

help [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-07-05 12:13 |只看该作者 |倒序浏览
我做了个简单的聊天系统:
talk.php:
-------------------------------------------------------------------------------
<html>;
<head>;
      <title>;聊天室</title>;
</head>;
<frameset rows="*,40" border=1>;
<frame src="display.php" name=display scrolling=auto>;
<frame src="write.php" name=write scrolling=no>;
<noframes>;
<body>;
</body>;
</noframes>;
</frameset>;
</html>;
--------------------------------------------------------------------------------------
write.php
------------------------------------------------------------------------------------
<?php                                                                                                         //这是文件write.php

$localhost="localhost";
$name="root";//用户
$password="";//密码,没有可以不填
$database="test";
$db=mysql_connect($localhost,$name,$password);
mysql_select_db($database,$db);

if (($username!=""and ($text!="") {
        $result=mysql_query("insert into talk  (username,text) values ('$_POST[username]','$_POST[text]')" or die(mysql_error());}

?>;
<html>;
<head>;
<title>;用户输入</title>;
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">;
</head>;
<body bgcolor="#FFFFFF" text="#000000">;
<form method="post" action="write.php">;
  <p>;
   你的ID: <input type="text" name="username"size="12">;
发言  <input type="text" name="text" size="57">;
<input type="submit" value="提交" >;</p>;
</form>;
</body>;
</html>;
-----------------------------------------------------------------------------------
display.php
--------------------------------------------------------------------------------------
<html>;
<meta http-equiv="refresh" content="10; url=<? Echo $php_self; ?>;">;
<body>;
<?
echo "<center>;<font size='5'>;欢迎光临我的聊天室</font>;";  
echo "<br>;";


$localhost="localhost";
$name="root";//用户
$password="";//密码,没有可以不填
$database="test";
$db=mysql_connect($localhost,$name,$password);
mysql_select_db($database,$db);


$result=mysql_query("select username,text from talk order by userid desc limit 0,20";     //执行
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='3'>;".$username." 说道: ".$text."</font>;</td>;";
            echo "</tr>;";
            echo "<br>;";}
            }                                                           //显示结果
else {
echo "对不起,系统故障!</body>;</html>;";}

?>;
</body>;
</html>;
--------------------------------------------------------------------------------------
数据库:
create table talk(
userid int(5) not null auto_increment,
username varchar(20) not null,
text varchar(50) not null,
primary key (userid)
);
---------------------------------------------------------------------------------
提交了100次了,还是没有把id和说话内容提到数据库中,只有"说道"两个字。
我在windows2000pro下iis+php+mysql,是不是我的mysql和php安装有问题呢?困惑啊!

我的电子邮箱:hwztime@sohu.com   hwztime@sina.com
qq:28741008请发到我的电子邮箱来谢谢,或者加我的qq告诉我答案。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP