国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

PHP和MYSQL聯合打造簡單留言本程序

2024-07-24 12:56:59
字體:
來源:轉載
供稿:網友

數據庫結構:(庫名:lyb)
表一: admin
字段: id(int11)   name(varchvr)   password(varchvr)

表二: 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>php和mysql聯合打造簡單留言本程序</title>
</head>
<link href="css.css" rel="stylesheet" type="text/css" />
<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">php和mysql聯合打造簡單留言本程序</div>
</div>

3 footer.php(公用底部文件)

<?php
$counterfile="conter.xml";
function displaycounter($counterfile){
$fp  =  fopen($counterfile,"rw");
$num =  fgets($fp,5);
$num += 1;
print "<div id=/"footer/">簡單留言板   您是第 "."$num"." 位無聊的銀</div>";
exec("rm -rf $counterfile");
exec("echo $num > $counterfile");
}
if(!file_exists($counterfile)){
exec("echo 0 > $counterfile");
}
displaycounter($counterfile);
?>
</body>
</html>

4 index.php(首頁)

<?php
require_once("conn.php");
require_once("header.php");
session_start();
//分頁代碼開始
$pagesize = 10;//設置每頁顯示條數
$rs = mysql_query("select count(*) from lo");//取得記錄總數,計算總頁數用
$myrow = mysql_fetch_array($rs);
$numrows = $myrow[0];//計算總記錄
$pages = intval($numrows/$pagesize);
if($numrows%$pagesize)$pages++;//設置頁數
if(isset($_get['page']))
    {
        $page = intval($_get['page']);
    }
    else
    {
        $page = 1;//設為第一頁
    }
$offset = $pagesize*($page-1);//計算記錄偏移量
//分頁代碼結束
$sql = "select id,username,sex,qq,email,info,ip,date_format(submit_time, '%y年%m月%d日 %t' ) from lo order by id desc limit $offset,$pagesize";//用到了date-format格式化日期格式
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num>0){
    while($row = mysql_fetch_array($result))
    {
    //echo print_r($row);
        if($row[2]=="男")//這個使性別改成你想要的名稱^_^
        {
            $sex = "帥鍋";
        }
        else
        {
            $sex = "美女";
        }
?>
<div id="show">
    <p class="num">第 [<?= $row[0] ?>] 條留言<p>
    <p class="unline">留言人:<span class="blue"><?= $row[1]?></span>  性別:<?= $sex ?>  留言時間:<?= $row[7] ?> <? if($row[3]) {?> <a href="http://wpa.qq.com/msgrd?v=1&uin=<?= $row[3] ?>&site=http://m.survivalescaperooms.com&menu=yes"><img src="http://m.survivalescaperooms.com/htmldata/2007-05-24/img/qq.gif" alt="<?= $row[3]?>" /></a><? } ?><? if($row[4]){ ?> <a href="mailto:<?= $row[4] ?>"><img src="http://m.survivalescaperooms.com/htmldata/2007-05-24/img/email.gif" alt="<?= $row[4]?>" /></a> <? }?><? if($_session["key"]==1){ ?> ip:<?= $row[6] ?>  <a href="update.php?wuleying&id=<?= $row[0]?>">更改</a> <a href="delete.php?wuleying&id=<?= $row[0]?>">刪除</a><?}?></a></p>
    <p class="blue">留言內容:</p>
    <div id="show_info"><?= nl2br(htmlspecialchars($row[5])) ?></div>
</div>
<?php
    }
}
else
    {
        echo "<div id=/"show/">無數據......</div>";
    }
?>
<div id="show_page">
<p>
<?php
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if($page==1&&$pages>1)
{
    echo "首頁 | ";
    echo "上一頁 | ";
    echo "<a href=/"index.php?page=".$next."/">下一頁</a> | ";
    echo "<a href=/"index.php?page=".$last."/">尾頁</a> | ";
}
elseif($page>=1&&$page!=$pages&&$num>0)
{
    echo "<a href=/"index.php?page=".$first."/">首頁</a> | ";
    echo "<a href=/"index.php?page=".$prev."/">上一頁</a> | ";
    echo "<a href=/"index.php?page=".$next."/">下一頁</a> | ";
    echo "<a href=/"index.php?page=".$last."/">尾頁</a> | ";
}
elseif($page==$pages&&$page!=1)
{
    echo "<a href=/"index.php?page=".$first."/">首頁</a> | ";
    echo "<a href=/"index.php?page=".$prev."/">上一頁</a> | ";
    echo "下一頁 | ";
    echo "尾頁 | ";
}
elseif($page==$pages)
{
    echo "首頁 | ";
    echo "上一頁 | ";
    echo "下一頁 | ";
    echo "尾頁 | ";   
}
else
{
    echo "首頁 | ";
    echo "上一頁 | ";
    echo "下一頁 | ";
    echo "尾頁 | ";
}
?>
共 <span><?= $pages ?></span> 頁 | 當前第 <span><?= $page ?></span> 頁 | 共 <span><?=$numrows ?></span> 條留言</p>
</div>
<?php
mysql_close();
?>
<?php
require_once("footer.php");
?>

5 post.php(提交留言頁面)

<?
require_once("header.php");
?>
<div id="input">
<form method="post" action="input.php" name="form1">
    <h1>提交留言</h1>
    <p>姓名 :<input type="text" name="name" size="20" class="y" /> </p>
    <p>性別 :<input name="sex" type="radio" value="男" checked/> 帥鍋 <input type="radio" name="sex" value="女"/> 美女</p>
    <p>q q :<input type="text" name="qq" class="y" /> (可選填)</p>
    <p>email:<input type="text" name="email" class="y" /> (可選填)</p>
    <p>留言內容:</p>
    <p><textarea name="info" rows="5" cols="40"></textarea></p>
    <p class="cen">
        <input type="submit" value="偶填好了" />
        <input type="reset" value="偶要重寫">
    </p>
    <p class="cen1">留言板 version 1.0</p>
</form>
</div>
</body>
</html>

6 input.php(插入留言)

<?php
require_once("conn.php");
$username = $_post['name'];
$sex = $_post['sex'];
$qq = $_post['qq'];
$email = $_post['email'];
$info = $_post['info'];
if (strrpos($username,"<")!==false || strrpos($username,">")!==false||strrpos($username,"@")!==false||strrpos($username,"/"")!==false||strrpos($username,"'")!==false||strrpos($username,"_")!==false)
{
    echo "<script>alert('名稱不能有特殊字符!');location.href='post.php';</script>";
    exit();
}
if (!ereg("^[0-9]{0,}$",$qq))//用正則檢查qq格式
{
    echo "<script>alert('oicq信息有錯誤!必須是數字!');location.href='post.php';</script>";
    exit();
}
if($email)
{//如果填寫了郵箱就用正則檢查郵箱格式
    if (!ereg("^[a-za-z0-9_/-/.][email protected][a-za-z0-9/-]+/.[a-za-z0-9/-/.]+$",$email))
    {
        echo "<script>alert('email格式不正確!');location.href='post.php';</script>";
        exit();
    }
}
if(!$username)
{
    echo "<script>alert('名稱不能為空哦!');location.href='post.php';</script>";
    exit();
}
elseif(!$info)
{
    echo "<script>alert('留言不能為空哦!');location.href='post.php';</script>";
    exit();
}
else
{
    $ip = getenv('remote_addr');//獲取客戶端ip地址
    $sql = "insert into lo (username,sex,qq,email,info,ip,submit_time) values ('$username','$sex','$qq','$email','$info','$ip',now())";
    $result = mysql_query($sql);
    mysql_close();
    echo "<script>alert('提交成功!返回首頁');location.href='index.php';</script>";
}
?>

7 update.php(修改留言頁)

<?php
session_start();
require_once('conn.php');
require_once('header.php');
if($_session["key"]==1)
{
$id = $_get['id'];
$sql = "select * from lo where id= ".$id;
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<div id="update">
    <form action="updatepost.php?wuleying&id=<?= $row[0] ?>" method="post">
        <h1>修改留言</h1>
        <p>姓名:<input type="text" value="<?= $row[1]?>" name="name" class="y"></input></p>
        <p>留言:</p>
        <p><textarea  name="info" rows="5" cols="35"><?= $row[5] ?></textarea></p>
        <p class="cen"><input type="submit" value="偶要修改" /></p>
        <p class="cen1">留言板 version 1.0</p>
    </form>
<div>
<?php
}
else
{
header('location:index.php');
}
?>

8 updatepost(修改提交頁)

<?php
require_once('conn.php');
$username = $_post['name'];
$info = $_post['info'];
$id = $_get['id'];
//echo $id;
$sql = "update lo set username= '".$username."',info='".$info."' where id=".$id;
mysql_query($sql);
echo "<script>alert('修改成功!');location.href='index.php';</script>";
?>

9 delete.php(刪除留言頁)

<?php
session_start();
require_once('conn.php');
$id=$_get['id'];
if($_session["key"]==1)
{
$sql = "delete from lo where id=".$id;
mysql_query($sql);
echo "<script>location.href='index.php'</script>";
}
else
{
header('location:index.php');
}
?>

10 admin.php(管理登錄頁)

<?php
require_once('conn.php');
require_once('header.php');
?>
<div id="admin">
    <form method="post" action="adminpost.php">
    <h1>管理員登錄</h1>
        <p>姓名 : <input type="text" name="name" size="20" class="y" /> </p>
        <p>密碼 : <input type="password" name="password" size="20" class="y" /> </p>
        <p class="cen"><input type="submit" value="管理員登錄" /></p>
        <p class="cen1">留言板 version 1.0</p>
    </form>
</div>

11 adminpost.php(管理驗證頁)

<?php
session_start();
require_once('conn.php');
$name = $_post['name'];
$password = $_post['password'];
$sql = "select * from admin where name='".$name."'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if (strrpos($name,"<")!==false || strrpos($name,">")!==false||strrpos($name,"@")!==false||strrpos($name,"/"")!==false||strrpos($name,"'")!==false||strrpos($name,"_")!==false)
{
    echo "<script>alert('不能有特殊字符!');location.href='admin.php';</script>";
}
if($num)
{//如果用戶存在,就檢查密碼是否正確
    $rs = mysql_fetch_array($result);
    if($rs[2]!=$password)
    {
        echo "<script>alert('密碼不正確,請確認后輸入!');location.href='admin.php';</script>";
    }
    else
    {//用戶名,密碼都正確,注冊session變量,然后跳轉到首頁
        $_session["key"]=1;
        echo "<script>alert('登錄成功!');location.href='index.php';</script>";
    }
}
else
{//如果沒有這個用戶
    echo "<script>alert('沒有這個用戶,請確認后輸入!');location.href='admin.php';</script>";
}
?>

12 adminexit.php(退出管理頁)

<?php
session_start();
$_session["key"] = 0;//使session不為1,0為游客,1為管理員
header('location:index.php');
?>

只是些基本的東東,像md5加密,ubb,表情圖片,添加管理員賬號,回復留言(-_!!)等我都沒加上去,有興趣的同學可以完善下。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂平县| 上高县| 沾益县| 东兰县| 南丰县| 栾川县| 那曲县| 孟村| 邵阳县| 德州市| 额济纳旗| 镇江市| 搜索| 玉门市| 武夷山市| 安塞县| 兴安盟| 淅川县| 云梦县| 德保县| 昭觉县| 安西县| 平阳县| 庆元县| 辽宁省| 上饶县| 高安市| 安图县| 高青县| 沙雅县| 吉水县| 崇文区| 云安县| 贞丰县| 临沂市| 新蔡县| 玉林市| 石嘴山市| 大城县| 栾城县| 伊宁市|