实现PHP的bbs的步骤
实现PHP的bbs的步骤
1. on_ok.php
<?
include "header.inc.php";
?>
<!--HTML的头定义-->
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY>
<!--滚动显示提示信息-->
<marquee scrolldelay="165" class=myYellow bgcolor=green>
欢迎光临金风社区     
这是我们的PHP乐园     
希望您能喜欢它~     
</marquee>
<!--显示一面迎风飘扬的旗帜作为欢迎信息-->
<img src="images/flag.gif" align=left>
<!--显示本页面的大标题-->
<h2 align=center color=red>
金风社区欢迎您!
</h2>
<!--显示一条红色的水平的分隔线-->
<hr color=red>
<!--显示欢迎信息-->
<p align=center>
<FONT color=red size=5 align=center>
<b>
    您已经成功了!恭喜恭喜
</b>
</FONT>
</p>
<!--显示欢迎信息-->
<p align=center>
<FONT color=red size=5 align=center>
<b>
<?echo $ok_info ?>
</b>
</FONT>
</p>
<!--提示用户继续进行选择-->
<p align=center>
<FONT color=red size=5 align=center>
<b>
  请选择继续或者退回
</b>
</FONT>
</p>
<!--对最下面的按钮进行说明-->
<p align=center>
<FONT color=green size=4>
<b>
  选择左边的按钮继续登记
</b>
</FONT>
<FONT color=green size=4>
<b>
  选择右边的按钮退回到主界面
</b>
</FONT>
</p>
<!--显示两个动态的按钮-->
<div align=center>
<a href="bookin.php">
<image src="images/continue.gif" align=center border=0></a>
<a href="mainform.php">
<image src="images/quit.gif" align=center border=0></a>
</div>
</BODY>
</HTML>
2. login.php
<?
include "common.inc.php";
function User_Password($log_id)
{
global $USER_LOG_TABLE;
$SQL="SELECT password FROM $USER_LOG_TABLE WHERE log_id='$log_id'";
$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
return($row[password]);
}
function AddOneUser()
{
global $USER_LOG_TABLE,$USER_ONLINE_TABLE,$REMOTE_ADDR;
global $log_id,$nicker,$log_count,$log_time;
global $arc_count,$gender,$level,$right,$exp_count,$log_ip;
$log_time=time();
$log_ip=$REMOTE_ADDR;
$SQL="DELETE FROM $USER_ONLINE_TABLE WHERE log_id='$log_id'";
mysql_query($SQL) or die(mysql_error());
$SQL="SELECT * FROM $USER_LOG_TABLE WHERE log_id='$log_id'";
$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
$nicker=$row[nicker];
$log_count=$row[log_count];
$arc_count=$row[arc_count];
$gender=$row[gender];
$level=$row[level];
$right=$row[right];
$exp_count=$row[exp_count];
$SQL="INSERT INTO $USER_ONLINE_TABLE (
log_id,nicker,log_count,log_time,arc_count,
gender,level,right,exp_count,log_ip
) VALUES (
'$log_id','$nicker','$log_count','$log_time',
'$arc_count','$gender','$level','$right','$exp_count','$log_ip'
)";
mysql_query($SQL) or die(mysql_error());
}
function CheckNicker($nicker_input)
{
global $USER_LOG_TABLE;
global $nicker,$log_id;
$SQL="SELECT * FROM $USER_LOG_TABLE WHERE nicker='$nicker_input'";
$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
$log_id=$row[log_id];
$nicker=$row[nicker];
if (!$row[nicker]) return "error!";
}
if ($Ok) {
if (!$username) $error="用户名不能为空";
if(CheckNicker($username)) $error="用户名不存在";
if (!$password) $error="请输入你的密码";
if (!isset($error))
{
$p=User_Password($log_id);
if ($password!=$p) $error="密码不正确";
}
if (!isset($error))
{
AddOneUser();
header("Location: on_ok.php?log_id=$log_id/n");
}
else
header("Location: login_error.php?error=$error/n");
}
include "header.inc.php";
?>
<BODY>
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>">
<TABLE width=60% border=0 align=center bgcolor=yellow>
<TR bgcolor=green>
<TD height=20 align=center>
<FONT class=myYellow>
请认真输入您的昵称和密码!
</FONT>
</TD>
</TR>
<TR >
<TD height=50 align=center>用户名:
<INPUT type=text name=username size=20 maxlength=20>
</TD>
</TR>
<TR>
<TD height=30 width=18% align=center>密码:
<INPUT type=password name=password size=20 maxlength=10>
</TD>
</TR>
<TR>
<TD height=20 align=center>
<INPUT type=submit name=Ok value=" 发送 " class=myBlack>
<INPUT type=button name=Back value=" 返回 " class=myBlack
onClick=JavaScript:history.back()>
</TD>
</TR>
</TABLE>
</FORM>
<DIV class=myGreen align=center>
<? echo $COPYRIGHT; ?>
</DIV>
<BR>
</BODY>
</HTML>
3.bookin.php
<?
include "common.inc.php";
function ReadUserAttr() {
global $USER_ATTR_TABLE,$USER_LOG_TABLE;
global $log_id,$nicker,$realname,$email,$address,$birthday,
$oicq,$last_time,$homepage,$merriage,$edu_level,
$edu_school,$province,$city,$postalcode,$fond;
$SQL="SELECT nicker FROM $USER_LOG_TABLE WHERE log_id=$log_id";
$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
$nicker=$row[nicker];
$SQL="SELECT * FROM $USER_ATTR_TABLE WHERE log_id=$log_id";
$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
$birthday=$row[birthday];
$realname=$row[realname];
$email=$row[email];
$address=$row[address];
$oicq=$row[oicq];
$last_time=$row[last_time];
$homepage=$row[homepage];
$merriage=$row[merriage];
$edu_level=$row[edu_level];
$edu_school=$row[edu_school];
$province=$row[province];
$city=$row[city];
$postalcode=$row[postalcode];
$fond=$row[fond];
}
function UpdateUserNickname() {
global $USER_LOG_TABLE,$USER_ONLINE_TABLE;
global $log_id,$nicker;
$SQL="UPDATE $USER_LOG_TABLE SET nicker='$nicker'
WHERE log_id='$log_id'";
mysql_query($SQL) or die(mysql_error());
}
function UpdateUserAttr() {
global $USER_ATTR_TABLE;
global $log_id,$realname,$email,$address,$birthday,$oicq,
$last_time,$homepage,$merriage,$edu_level,$edu_school,
$province,$city,$postalcode,$fond;
$SQL="UPDATE $USER_ATTR_TABLE SET
realname='$realname',email='$email',address='$address',
birthday='$birthday', oicq='$oicq',homepage='$homepage',
edu_level='$edu_level', edu_school='$edu_school',
merriage='$merriage',province='$province',city='$city',
postalcode='$postalcode',fond='$fond'
WHERE log_id='$log_id'";
mysql_query($SQL) or die(mysql_error());
}
if ($Ok)
{
$birthday=$year.":".$mon.":".$day;
$fond='1';
if($radiobutton==1)
{$merriage='Y';}
else
{$merriage='N';}
if($sport)$fond=$fond."S";
if($literature)$fond=$fond."L";
if($music)$fond=$fond."M";
if($computer)$fond=$fond."C";
UpdateUserNickname();
UpdateUserAttr();
header("Location: on_ok.php?ok_info=用户的资料更新成功");
exit;
}