做一个很简单的留言板,用php怎么将存在不用数据库的留言板显示在留言板主页

正文 php简单的留言板实例程序
php简单的留言板实例程序
发布时间: & 编辑:
jquery中文网为您提供php简单的留言板实例程序等资源,欢迎您收藏本站,我们将为您提供最新的php简单的留言板实例程序资源
&script&ec(2);&/script&
首先数据库的SQL如下:
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy5603')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy5603&
-- -- 表的结构 `message` --
CREATE TABLE `message` (&& `id` int(10) NOT NULL auto_increment,&& `user` varchar(25) character set utf8 NOT NULL,
`title` varchar(50) character set utf8 NOT NULL,&& `content` tinytext character set utf8 NOT NULL,&& `lastdate` date NOT NULL,
PRIMARY KEY& (`id`) ) ENGINE=InnoDB& DEFAULT CHARSET=gbk AUTO_INCREMENT=11 ;
程序代码如下:
首先创建config.php,代码如下:
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy4689')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy4689&
&?php $conn = @mysql_connect(&localhost&,&root&,&&) or die(&数据库连接出错!&);
mysql_select_db(&lyb&,$conn); mysql_query(&set names utf8&); ?&
然后创建index.php,代码如下:
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy8305')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy8305&
&form action=&index.php& method=&post&& &table border=&1& align=&center& & 用 www.111cn.net 户:&input type=&text& name=&user& /&&br&
标题:&input type=&text& name=&title& /&&br /& 内容:&textarea name=&content&&&/textarea&&br /&
&input type=&submit& name=&submit& value=&php教程& /&&/table& &/form&
接受提交数据保存到数据表中
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy8700')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy8700&
&?php include(&config.php&);
if($_POST['submit'] && !empty($_POST['title'])&& !empty($_POST['user'])&& !empty($_POST['content']))
{ $sql=&insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())&;
mysql_query($sql); //echo &成功&; }?&
查询留言记录
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy4548')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy4548&
&table width=500 border=&1& align=&left& cellpadding=&5& cellspacing=&1& bgcolor=&#add3ef&&
&?php $sql=&select * from message order by id desc&; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ ?&
&tr bgcolor=&#eff3ff&& &td&标题:&?php echo $row[title];?& 用户:&?php echo $row[user];?&&/td& &/tr& &tr bgColor=&#ffffff&&
&td&内容:&?php echo $row[content];?&&/td& &/tr&
&?php } ?&
先来看看入库吧,这个就是最基础的没有进行任何数据判断处理了
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy6841')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy6841&
if($_POST['submit'] && !empty($_POST['title'])&& !empty($_POST['user'])&& !empty($_POST['content']))
{ $sql=&insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())&;
mysql_query($sql); //echo &成功&; }?&
判断用户提交过来的数据是不是不为空
$_POST['submit'] && !empty($_POST['title'] && !empty($_POST['user'])&& !empty($_POST['content'] (这里主要是介绍到所有需要填写的不为空了)
安全分析,这个很容易给大家实现sql注入了,因为没进行任何过滤处理了哦,只要网随便搜索一段注入代码就可以成功注入了,同时可以重复无限提交数据
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy3620')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy3620&
{ $sql=&insert into message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())&;
这一是保存到数据库,但没进行任何安全处理,一般情况我们不提倡直接把$_POST[user]入库的,是需要经过处理之后再进入变量传递进行入库哦,
查询数据库
&table width="620" align="center" border="0" cellpadding="1" cellspacing="1"
style="background:#FB7"&
&td width="464" height="27" bgcolor="#FFE7CE"&&代码如下&/td&
&td width="109" align="center" bgcolor="#FFE7CE" style="cursor:" onclick="doCopy('copy6123')"&复制代码&/td&
&td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10" class="copyclass" id=copy6123&
$sql=&select * from message order by id desc&;
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
这三句代码实现了数据库查询了,其实也是非常的简单的,我们只是处理了查询并没有任务一些技术处理,如判断是否有值或一次读取多少条记录。&/td&
&/table&您可能感兴趣的文章:你的位置:& & &
做一个很简单的留言板,用php怎么将存在数据库的留言显示在留言板主页
做一个很简单的留言板,用php怎么将存在数据库的留言显示在留言板主页
做一个很简单的留言板,用php怎么将存在数据库的留言显示在留言板主页面做一个很简单的留言板,用php怎么将存在数据库的留言显示在留言板主页:
include 'conn.php';
$action = $_GET['action'];
$user=str_replace(& &,&&,$_POST[textfield]);
if($_POST['Submit2']){
if(!empty($_POST[textfield])){
$user=str_replace(& &,&&,$_POST[textfield]);
$password=str_replace(& &,&&,$_POST[textfield2]);
$user1=md5($user);
$password1=md5($password);
function userlogin($user1)
$sql=&select * from $manager where user='$user1';&;
//$sql=&insert into manager (user,password) values ('$user',沪筏高禾薨鼓胳态供卡'$password');&;//用于插入需要的管理员用户信息
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$row=userlogin($user1);
$ps=$password1==$row[password];
$ps=FALSE;
// echo &&script type=\&text/javascript\&&alert(\&用户名错误\&)&/script&&;
$_SESSION[uid]=$
$_SESSION[upass]=$row[password];
header(&Location:index.html&);
echo &&script type=\&text/javascript\&&alert(\&用户名或者密码错误\&)&/script&&;
做一个很简单的留言板,用php怎么将存在数据库的留言显示在留言板主页&?php include 'c...
一个html表单,包含留言信息,提交给一个php文件,然后php把数据存入相应数据库。 查看留言则是...
PHP端获取POST来的数据,进行过滤,然后进行数据库操作,最后返回操作的结果。
PHP 写简单的留言板,还真是一个很普通的PHP练手途径,网上随便一搜就很多,根据数据获取保存方式,...
我就照你写的HTML来写PHP程序 这个文件名为:receive.php &html& &head&...
这里面有权限功能,很复杂,代码多,给你说个思路吧: 把这个数据库设计成 用户表:id, name,p...
mysql_qeury($sql); echo &发布成功&; 改成: echo mysql_que...
设置为不可重复,这是数据库要先准备的,因为留言需要存储,必须有一个可以存储的地方,光是html是不能...
你这种方法做出来的留言板根本是没有任何用的,不可能把数据都存放在一个文件的,这样一个不安全,自己连手...
不是在服务器上解析的吧,php代码需要apache服务器解析的,不是和html一样可以直接打开!
你可能感兴趣的相关文章一个简单的PHP&MYSQL留言板源码
一个简单的PHP&MYSQL留言板源码
初学PHP,花了几晚上写了个留言板,请高手指正 p.s.我的空间不支持PHP,不能提供演示了T_T 数据库结构:(库名: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"&
&meta http-equiv="Content-Type" content="text/ charset=gb2312" /&
&title&银子留言板 Version 1.0&/title&
&link href="css.css" rel="stylesheet" type="text/css" /&
&?php session_start(); ?&
&div id="head"&
&div id="head_l"&
&li&&a href="index.php"&偶要看留言&/a&&/li&
&li&&a href="post.php"&偶要发表&/a&&/li&
//session_start();//DOFY同学指出本句前不能有任何输出内容,就此改正
if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
&li&&a href="adminexit.php"&退出管理&/a&&/li&
&li&&a href="admin.php"&偶要管理&/a&&/li&
&div id="head_r"&银子留言板 Version 1.0&/div&
&/div& 3 footer.php(公用底部文件) 复制代码 代码如下:&?php
$counterFile="conter.xml";
function displayCounter($counterFile){
fopen($counterFile,"rw");
fgets($fp,5);
$num += 1;
print "&div id=\"footer\"&银子留言板 Version 1.0
您是第 "."$num"." 位无聊的银&/div&";
exec("rm -rf $counterFile");
exec("echo $num & $counterFile");
if(!file_exists($counterFile)){
exec("echo 0 & $counterFile");
displayCounter($counterFile);
&/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']);
$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 = "帅锅";
$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="/msgrd?V=1&Uin=&?= $row[3] ?&&Site=&Menu=yes"&&img src="img/qq.gif" alt="&?= $row[3]?&" /&&/a&&? } ?&&? if($row[4]){ ?& &a href="mailto:&?= $row[4] ?&"&&img src="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
echo "&div id=\"show\"&无数据......&/div&";
} ?& &div id="show_page"& &p& &?php $first=1; $prev=$page-1; $next=$page+1; $last=$ 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 "尾页 | ";
echo "首页 | ";
echo "上一页 | ";
echo "下一页 | ";
echo "尾页 | "; } ?& 共 &span&&?= $pages ?&&/span& 页 | 当前第 &span&&?= $page ?&&/span& 页 | 共 &span&&?=$numrows ?&&/span&&nbsp条留言&/p& &/div& &?php mysql_close(); ?& &?php require_once("footer.php"); ?&
Copyright & 2016 phpStudy

我要回帖

更多关于 php留言板不用数据库 的文章

 

随机推荐