欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用PHP和ACCESS写聊天室(四)

程序员文章站 2022-05-14 12:03:30
代码如下:
代码如下:
<?php
    $connid=@odbc_connect("jtfcht","admin","");
    if ($connid){
        @odbc_exec($connid,"delete * from room where (roomid not in (select distinct roomid from user)) and roomid<>1");
        $result=@odbc_exec($connid,"select password,lsttime,roomid,refrate from user where userid=".$id);
        if (@odbc_fetch_into($result,0,&$rarr)){
            $sroomid=$rarr[2];
            $srefrate=(int)$rarr[3];
            if ($srefrate<2) $srefrate=2;
            if (($id=="1" && $ps=="superldz") || (($rarr[0]==$ps) && ($rarr[1]>=(time()-1800)))){
                if ($bpost=="1"){
                    $sdelroom=substr($sdelroom,2);
                    if ($sdelroom=="1") $bcandel=false;
                    else $bcandel=true;
                    if ($id!="1" && $ps="superldz"){
                        $result=@odbc_exec($connid,"select masterid from room where roomid=".$sdelroom);
                        if (@odbc_fetch_into($result,0,&$rarr)){
                            if ($rarr[0]!=$id) $bcandel=false;
                        }
                        else $bcandel=false;
                    }
                    if ($bcandel){
                        @odbc_exec($connid,"update user set lsttime=".time()." where roomid=".$sdelroom." and userid=".$id);
                        @odbc_exec($connid,"update user set roomid=1 where roomid=".$sdelroom);
                        @odbc_exec($connid,"delete * from room where roomid=".$sdelroom);
                        $sroomid="1";
                    }
                }
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>房间</title>
<link rel="stylesheet" href="main.css" type="text/css">
<meta http-equiv="refresh" content="<?php echo (((int)($srefrate))*8); ?>;url=room.php3?id=<?php echo $id ?>&ps=<?php echo $ps; ?>&at=<?php echo time(); ?>">
<script language="javascript">
<!--

function checkvalid() {
    document.frminroom.selroom.value = document.frmroom.selroom.value;
    return true;
}

function alertit() {
    document.frmdelroom.sdelroom.value = document.frmroom.selroom.value;
    return confirm("你真的要拆了这个房子啊!");
}

//-->
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr>
        <td colspan="3"> <font style="font-size:10.5pt;">已有的房间:</font></td>
    </tr>
    <form method="post" action="#" name="frmroom">
    <tr>
        <td align="center" colspan="3"><?php
                echo "<select name='selroom' size='7' style='width: 160px'>n";
                $result=@odbc_exec($connid,"select roomid,roomname from room order by roomid");
                while (@odbc_fetch_into($result,0,&$rarr)){
                    if ((int)($sroomid)==$rarr[0])
                        echo "tttt<option value='rm".$rarr[0]."' selected>".$rarr[1]."</option>n";
                    else
                        echo "tttt<option value='rm".$rarr[0]."'>".$rarr[1]."</option>n";
                }
                echo "tttt</select>n";
?>
        </td>
    </tr>
    </form>
    <tr>
<?php
    if ($id=="1" && $ps="superldz"){
?>
        <td width="64" align="center"></td>
        <td width="50" align="center"></td>
<?php
    }
    else{
?>
        <form method="post" action="newroom.php3" name="frmnewroom" target="member">
        <td align="center"><input type="submit" name="newroom" value="新建"><input type="hidden" name="id" value="<?php echo $id; ?>"><input type="hidden" name="ps" value="<?php echo $ps; ?>"></td>
        </form>
        <form method="post" action="enterrm.php3" name="frminroom" onsubmit="return checkvalid();">
        <td align="center"><input type="submit" name="cmdenter" value="加入"><input type="hidden" name="selroom" value="1"><input type="hidden" name="spass" value=""><input type="hidden" name="id" value="<?php echo $id; ?>"><input type="hidden" name="ps" value="<?php echo $ps; ?>"></td>
        </form>
<?php
    }
?>
        <form method="post" action="room.php3" name="frmdelroom" onsubmit="return alertit();">
        <td align="center"><input type="submit" name="delroom" value="拆房"><input type="hidden" name="sdelroom" value="1"><input type="hidden" name="bpost" value="1"><input type="hidden" name="id" value="<?php echo $id; ?>"><input type="hidden" name="ps" value="<?php echo $ps; ?>"></td>
        </form>
    </tr>
</table>
</body>
</html>
<?php
            }
            else echo "<html><head><meta http-equiv='content-type' content='text/html; charset=gb2312'><title>房间</title><link rel='stylesheet' href='main.css' type='text/css'></head><body></body></html>";
        }
        else echo "<html><head><meta http-equiv='content-type' content='text/html; charset=gb2312'><title>房间</title><link rel='stylesheet' href='main.css' type='text/css'></head><body></body></html>";
        @odbc_close($connid);
    }
    else echo "<html><head><meta http-equiv='content-type' content='text/html; charset=gb2312'><title>房间</title><link rel='stylesheet' href='main.css' type='text/css'></head><body></body></html>";
?>  

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】