加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

来自经典的打造简单的PHPMYSQL留言板

发布时间:2020-05-29 00:17:49 所属栏目:PHP 来源:互联网
导读:比较简单易懂的php+mysql留言板数据库结构:(库名: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(连接数据库文件)
<div class="codetitle"><a style="CURSOR: pointer" data="96827" class="copybut" id="copybut96827" onclick="doCopy('code96827')"> 代码如下:<div class="codebody" id="code96827">
<?php
mysql_connect("localhost","root","");//连接数据库
mysql_select_db("lyb");//选择数据库
?>

2、header.php(公用头部文件)
<div class="codetitle"><a style="CURSOR: pointer" data="88541" class="copybut" id="copybut88541" onclick="doCopy('code88541')"> 代码如下:<div class="codebody" id="code88541">
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<htmlxmlns="http://www.w3.org/1999/xhtml"&gt;

<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
银子留言板Version1.0

<linkhref="css.css"rel="stylesheet"type="text/css"/>

<divid="head">
<divid="head_l">


  • <ahref="index.php">偶要看留言

  • <ahref="post.php">偶要发表

  • <?php
    session_start();
    if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
    ?>
  • <ahref="adminexit.php">退出管理

  • <?
    }
    else
    {
    ?>
  • <ahref="admin.php">偶要管理

  • <?}?>


<divid="head_r">银子留言板Version1.0


3、footer.php(公用底部文件)
<div class="codetitle"><a style="CURSOR: pointer" data="66515" class="copybut" id="copybut66515" onclick="doCopy('code66515')"> 代码如下:<div class="codebody" id="code66515">
<?php
$counterFile="conter.xml";
functiondisplayCounter($counterFile){
$fp=fopen($counterFile,"rw");
$num=fgets($fp,5);
$num+=1;
print"<divid="footer">银子留言板Version1.0您是第"."$num"."位无聊的银";
exec("rm-rf$counterFile");
exec("echo$num>$counterFile");
}
if(!file_exists($counterFile)){
exec("echo0>$counterFile");
}
displayCounter($counterFile);
?>

4、index.php(首页)
<div class="codetitle"><a style="CURSOR: pointer" data="6036" class="copybut" id="copybut6036" onclick="doCopy('code6036')"> 代码如下:<div class="codebody" id="code6036">
<?php
require_once("conn.php");
require_once("header.php");
session_start(); //分页代码开始
$pagesize=10;//设置每页显示条数
$rs=mysql_query("selectcount()fromlo");//取得记录总数,计算总页数用
$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="selectid,username,sex,qq,email,info,ip,DATE_FORMAT(submit_time,'%Y年%m月%d日%T')fromloorderbyiddesclimit$offset,$pagesize";//用到了DATE-FORMAT格式化日期格式
$result=mysql_query($sql);
$num=mysql_num_rows($result); if($num>0){
while($row=mysql_fetch_array($result))
{
//echoprintr($row);
if($row[2]=="男")//这个使性别改成你想要的名称^
^
{
$sex="帅锅";
}
else
{
$sex="美女";
}
?> <divid="show">
<pclass="num">第[<?=$row[0]?>]条留言


<pclass="unline">留言人:<spanclass="blue"><?=$row[1]?>性别:<?=$sex?>留言时间:<?=$row[7]?><?if($row[3]){?><ahref="http://wpa.qq.com/msgrd?V=1&Uin=<?=$row[3]?>&Site=http://www.loai.cn&Menu=yes"&gt;<imgsrc="img/qq.gif"alt="<?=$row[3]?>"/><?}?><?if($row[4]){?><ahref="mailto:<?=$row[4]?>"><imgsrc="img/email.gif"alt="<?=$row[4]?>"/><?}?><?if($_SESSION["key"]==1){?>IP:<?=$row[6]?><ahref="update.php?wuleying&id=<?=$row[0]?>">更改<ahref="delete.php?wuleying&id=<?=$row[0]?>">删除<?}?>


<pclass="blue">留言内容:


<divid="show_info"><?=nl2br(htmlspecialchars($row[5]))?>

<?php
}
}
else
{
echo"<divid="show">无数据......";
}
?> <divid="show_page">


<?php
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if($page==1&&$pages>1)
{
echo"首页|";
echo"上一页|";
echo"<ahref="index.php?page=".$next."">下一页|";
echo"<ahref="index.php?page=".$last."">尾页|";
}
elseif($page>=1&&$page!=$pages&&$num>0)
{
echo"<ahref="index.php?page=".$first."">首页|";
echo"<ahref="index.php?page=".$prev."">上一页|";
echo"<ahref="index.php?page=".$next."">下一页|";
echo"<ahref="index.php?page=".$last."">尾页|";
}
elseif($page==$pages&&$page!=1)
{
echo"<ahref="index.php?page=".$first."">首页|";
echo"<ahref="index.php?page=".$prev."">上一页|";
echo"下一页|";
echo"尾页|";
}
elseif($page==$pages)
{
echo"首页|";
echo"上一页|";
echo"下一页|";
echo"尾页|";
}
else
{
echo"首页|";
echo"上一页|";
echo"下一页|";
echo"尾页|";
}
?>
共<?=$pages?>页|当前第<?=$page?>页|共<?=$numrows?>&nbsp条留言



<?php
mysql_close();
?> <?php
require_once("footer.php");
?>

5、post.php(提交留言页面)
<div class="codetitle"><a style="CURSOR: pointer" data="87473" class="copybut" id="copybut87473" onclick="doCopy('code87473')"> 代码如下:<div class="codebody" id="code87473">
<?
require_once("header.php");
?>
<divid="input">
<formmethod="post"action="input.php"name="form1">

提交留言


姓名:<inputtype="text"name="name"size="20"class="y"/>


性别:<inputname="sex"type="radio"value="男"checked/>帅锅<inputtype="radio"name="sex"value="女"/>美女


QQ :<inputtype="text"name="qq"class="y"/>(可选填)


Email:<inputtype="text"name="email"class="y"/>(可选填)


留言内容:


<textareaname="info"rows="5"cols="40">


<pclass="cen">
<inputtype="submit"value="偶填好了"/>
<inputtype="reset"value="偶要重写">


<pclass="cen1">银子留言板Version1.0






6、input.php(插入留言)
<div class="codetitle"><a style="CURSOR: pointer" data="69719" class="copybut" id="copybut69719" onclick="doCopy('code69719')"> 代码如下:<div class="codebody" id="code69719">
<?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"";
exit();
} if(!ereg("^[0-9]{0,}$",$qq))//用正则检查QQ格式
{
echo"";
exit();
} if($email)
{//如果填写了邮箱就用正则检查邮箱格式
if(!ereg("^[a-zA-Z0-9_-.]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$",$email))
{
echo"";
exit();
}
} if(!$username)
{
echo"";
exit();
}
elseif(!$info)
{
echo"";
exit();
}
else
{
$ip=getenv('REMOTE_ADDR');//获取客户端IP地址 $sql="insertintolo(username,submit_time)values('$username','$sex','$qq','$email','$info','$ip',NOW())"; $result=mysql_query($sql); mysql_close(); echo"";
}
?>

7、update.php(修改留言页)
<div class="codetitle"><a style="CURSOR: pointer" data="96422" class="copybut" id="copybut96422" onclick="doCopy('code96422')"> 代码如下:<div class="codebody" id="code96422">
<?php
session_start();
require_once('conn.php');
require_once('header.php');
if($_SESSION["key"]==1)
{
$id=$_GET['id'];
$sql="selectfromlowhereid=".$id;
$result=mysql_query($sql);
$row=mysql_fetch_array($result); ?> <divid="update">
<formaction="updatepost.php?wuleying&id=<?=$row[0]?>"method="post">

修改留言


姓名:<inputtype="text"value="<?=$row[1]?>"name="name"class="y">


留言:


(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读