Maison > Article > développement back-end > 用PHP和ACCESS写聊天室(五)_PHP教程
member.php3 :
function delquot($sStr){
$s=str_replace(chr(124),"",$sStr);
$s=str_replace(chr(39),"",$s);
$s=str_replace(chr(34),"",$s);
return $s;
}
$ConnID=@odbc_connect("jtfcht","admin","");
if ($ConnID){
@odbc_exec($ConnID,"UPDATE User SET RoomID=0,ToID=0,ToName='',Secret=False,FirstTime=False,LstTime=0,LastLoc=0 WHERE (NOT (UserID=1)) AND LstTime $result=@odbc_exec($ConnID,"SELECT PassWord,LstTime,RoomID,RefRate,ToID FROM User WHERE UserID=".$id);
if (@odbc_fetch_into($result,0,&$rArr)){
$sRoomID=$rArr[2];
$sRefRate=(int)$rArr[3];
$sToID=$rArr[4];
if ($sRefRate if (($id=="1" && $ps=="superldz") || (($rArr[0]==$ps) && ($rArr[1]>=(time()-1800)))){
switch ($ptp){
case "1":
$bYes=true;
$sErr="";
$sRoom=htmlspecialchars(trim(delquot($sRoom)));
if ($sPass1!=$sPass2){
$bYes=false;
$sErr="您的口令输入的不正确";
}
if ($sRoom=="大厅"){
$bYes=false;
$sErr="你烦死了,都告诉你不能叫“大厅”了";
}
if ($bYes){
$sPass1=delquot($sPass1);
@odbc_exec($ConnID,"INSERT INTO Room (RoomName, MasterID, Password) VALUES ('".$sRoom."', ".$id.", '".$sPass1."')");
if ($php_errormsg=="SQL error: [Microsoft][ODBC Microsoft Access 97 Driver] The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate, SQL state 23000 in SQLExecDirect"){
$bYes=false;
$sErr="这个房间已经有了";
}
else{
$result=@odbc_exec($ConnID,"SELECT RoomID FROM Room WHERE RoomName = '".$sRoom."'");
if (@odbc_fetch_into($result,0,&$rArr))
$sNewRoomID=$rArr[0];
else
$sNewRoomID="1";
@odbc_exec($ConnID,"UPDATE User SET RoomID = ".$sNewRoomID.",ToID=0,ToName='大家' WHERE UserID=".$id);
if ((int)$sRoomID!=1){
$result=@odbc_exec($ConnID,"SELECT COUNT(UserID) FROM User WHERE RoomID=".$sRoomID);
@odbc_fetch_into($result,0,&$rArr);
if ($rArr[0]==0) @odbc_exec($ConnID,"DELETE * FROM Room Where RoomID=".$sRoomID);
}
$sRoomID=$sNewRoomID;
}
}
if (!$bYes){
?>
璇烽