- 论坛徽章:
- 0
|
我做了个简单的聊天系统:
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告诉我答案。 |
|