打造简单的PHP&MYSQL留言板

时间:2008-04-21 16:59:00   来源:   作者:

数据库结构:(库名:lyb) http://www.cnjiaocheng.com

表一: admin
字段: id(int11)   name(varchvr)   password(varchvr) http://www.cnjiaocheng.com

表二: lo
字段: id(int11)   username(varchvr)  sex(varchvr)  qq(varchvr)  email(varchvr)  info(text)  ip(varchvr)  submit_time(datetime)

来源中国教程网

1、conn.PHP(连接数据库文件)

来源中国教程网

<?PHP
mysql_connect("localhost","root","");//连接数据库
mysql_select_db("lyb");//选择数据库
?>
来源中国教程网

2、header.PHP(公用头部文件) 来源中国教程网

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML XMLns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/HTML; charset=gb2312" />
<title>银子留言板 Version 1.0</title>
</head>
<link href="../../CSS.CSS" rel="stylesheet" type="text/CSS" /> http://www.cnjiaocheng.com
<body>
<div id="head">
    <div id="head_l">
        <ul>
            <li><a href="index.PHP">偶要看留言</a></li>
            <li><a href="post.PHP">偶要发表</a></li>
            <?PHP
            session_start();
            if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
            ?>
            <li><a href="adminexit.PHP">退出管理</a></li>

来源中国教程网

            <?
            }
            else
            {
            ?>
            <li><a href="admin.PHP">偶要管理</a></li>
            <?}?>
        </ul>
    </div>
    <div id="head_r">银子留言板 Version 1.0</div>
</div>
http://www.cnjiaocheng.com

3、footer.PHP(公用底部文件)

http://www.cnjiaocheng.com

http://www.cnjiaocheng.com

<?PHP
$counterFile="conter.XML";
function displayCounter($counterFile){
$fp  =  fopen($counterFile,"rw");
$num =  fgets($fp,5);
$num += 1;
print "<div id=\"footer\">银子留言板 Version 1.0&nbsp;&nbsp;&nbsp;您是第&nbsp;"."$num"."&nbsp;位无聊的银</div>";
exec("rm -rf $counterFile");
exec("echo $num > $counterFile");
}
if(!file_exists($counterFile)){
exec("echo 0 > $counterFile");
}
displayCounter($counterFile);
?> 来源中国教程网

</body>
</HTML>

http://www.cnjiaocheng.com