时间:2021-07-01 10:21:17 帮助过:33人阅读
<html> <head> <title>用户登录</title> </head> <body>请输入您的昵称<br> <form action="main.php" method="post" target="_self"> <input type="text" name="nick" cols="20"> <input type="submit" value="登录"> </body> </html> |
<? setcookie("nick",$nick) //用cookie记录用户昵称,是常用的传递变量方法 ?> <html> <title>山西铝厂聊天室试用版ver1.0</title> <frameset rows="80%,*"> <frame src=" cdisplay.php" name="chatdisplay"> <frame src="speak.php" name="speak"> </frameset> </html> |
<html> <head> <title>显示用户发言</title> <meta http-equiv="refresh" content="5;url=cdisplay.php"> </head> <body> <? $link_ID=mysql_connect("main","root"); //链接Mysql服务器 服务器名为main,管理员名为root mysql_select_db("abc"); //选择数据库 $str="select * from chat ORDER BY chtime;" ; //查询字符串 $result=mysql_query($str, $link_ID); //送出查询 $rows=mysql_num_rows($result); //取得查询结果的记录笔数 //取得最后15笔发言,并显示 @mysql_data_seek($resut,$rows-15); //移动记录指针到前15笔记录 if ($rows<15) $l=$rows; else $l=15; //记录总数小于15,则最多为该记录数 for ($i=1;$i<=$l;$i++) { list($chtime,$nick,$words)=mysql_fetch_row($result); echo $chtime; echo " ";echo $nick; echo":" ; echo $words; echo "<BR>"; } //清除库中过时的数据 @mysql_data_seek($result,$rows-20); //移动记录指针到前20笔记录 list($limtime)=mysql_fetch_row($result); $str="DELETE FROM chat WHERE chtime<'$limtime' ;" ; $result=mysql_query($str,$link_ID); //送出查询字符串,库中只留前20个记录 mysql_close($link_ID); ?> </body> </html> |
<html> <head> <title>发言</title> </head> <body> <? If ($words) { $link_ID=mysql_connect("main","root"); mysql_select_db("abc"); //数据库名为abc $time=date(y).date(m).date(d).date(h).date(i).(date(s); //取得当前时间 $str="INSERT INTO chat(chtime,nick,words) values ('$time','$nick','$words');" ; mysql_query($str,$link_ID); //送出发言到数据库 mysql_close($link_ID); } ?> //输入发言的表单 <form action="speak.php" method="post" target=" _self"> <input type="text" name="words" cols="20"> <input type="submit" value="发言"> </form> </body> </html> |