PHP留言小练习
实现功能:
留言、搜索、编辑、删除、详情页、时间、点击量
页面划分:
index.html(留言列表页)
add.html(留言页)
edit.php(编辑页)
del.php(删除页)
view.php(详情页)
conn.php(数据库连接)
数据字段:
视图呈现:
代码展现:
index.php
<link rel="stylesheet" href="css/main.css">
<div class="g-wrap">
<div class="m-top">
<a class="mt-link" href="add.php">留言</a>
<div class="mt-search">
<form action="" name="keys">
<input type="text" name="keys">
<input type="submit" value="搜索">
</form>
</div>
</div>
<div class="m-con">
<ul class="m-infor">
<?php
include("conn.php");//引入数据库
if(!empty($_GET['keys'])){
$w = " `title` like '%".$_GET['keys']."%' ";
}
else{
$w = 1;
}
$sql = "select * from `news` where $w order by id desc limit 10";//倒序显示10条,where 1表示没有任何条件和不写一样
$query = mysql_query($sql);//执行sql语句并返回资源
//$rs = mysql_fetch_array($query);//返回双重数组,下标和键名都有,每执行一次得到一条
while( ($rs = mysql_fetch_array($query)) != false ){
?>
<li class="mi-list">
<h3 class="ml-top">
<a href="view.php?id=<?php echo $rs['id']; ?>">
<?php echo $rs['title']; ?>
</a>
</h3>
<div class="ml-cen">
<?php echo iconv_substr($rs['contents'],0,10,"gbk"); ?>...
</div>
<div class="ml-bot">
<span class="mb-l"><?php echo $rs['dates']; ?></span>
<div class="mb-r">
<a href="edit.php?id=<?php echo $rs['id']; ?>">编辑</a>
<a href="del.php?del=<?php echo $rs['id']; ?>">删除</a>
</div>
</div>
</li>
<?php
}
?>
</ul>
</div>
</div>
add.php
<link rel="stylesheet" href="css/main.css">
<?php
include("conn.php");//引入链接数据库
if( !empty($_POST["sub"]) ){//第一次返回真empty($_POST["sub"])这里也可以用其他值判断
$title = $_POST['title'];
$con = $_POST['con']; $sql = "insert into `news` (`id`,`title`,`dates`,`contents`,`hits`) values (null,'$title',now(),'$con',0)"; mysql_query($sql);//执行sql语句 $url = "./index.php"; echo "<script>location.href='".$url."';</script>";
//print_r($sql);
}
?>
<div class="g-wrap">
<div class="m-form">
<form action="add.php" method="post">
<ul>
<li>
<label for="">标题:</label>
<input type="text" name="title">
</li>
<li>
<label for="">内容:</label>
<textarea id="" cols="30" rows="10" name="con"></textarea>
</li>
<li>
<input type="submit" name="sub" value="发表">
</li>
</ul>
</form>
</div>
</div>
edit.php
<link rel="stylesheet" href="css/main.css">
<?php
include("conn.php");
if( !empty($_GET['id']) ){
$sql = "select * from news where `id`='".$_GET['id']."'";
$query = mysql_query($sql);//执行sql语句 $rs = mysql_fetch_array($query);
//print_r($rs);
}
//执行update语句
if(!empty($_POST["sub"])){//第一次返回真empty($_POST["sub"])这里也可以用其他值判断 这里只有点提交的时候才执行嘛 $title = $_POST['title'];
$con = $_POST['con'];
$hid = $_POST['hid'];//这里也可以通过get获取值与之对应起来
$sql = "update `news` set `title`='$title',`contents`='$con' where id='$hid' limit 1 "; mysql_query($sql);//执行sql语句 //echo "更新成功";
echo "<script>alert('更新成功!');location.href='index.php';</script>";
}
?>
<div class="g-wrap">
<div class="m-form">
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']; ?>">
<ul>
<li>
<label for="">标题:</label>
<input type="text" name="title" value="<?php echo $rs['title']; ?>">
</li>
<li>
<label for="">内容:</label>
<textarea id="" cols="30" rows="10" name="con"><?php echo $rs['contents']; ?></textarea>
</li>
<li>
<input type="submit" name="sub" value="发表">
</li>
</ul>
</form>
</div>
</div>
del.php
<?php
include("conn.php"); if(!empty($_GET['del'])){//empty()当为空时返回真
$d = $_GET['del'];
$sql = "delete from `news` where `id`='$d'"; mysql_query($sql);//执行sql语句
$url = "./index.php";
echo "<script>alert('删除成功!');location.href='".$url."';</script>";
}
?>
view.php
<link rel="stylesheet" href="css/main.css">
<?php
include("conn.php");//引入链接数据库
if(!empty($_GET['id'])){
$sql = "select * from news where `id`='".$_GET['id']."'";
$query = mysql_query($sql);//执行sql语句 $rs = mysql_fetch_array($query); //print_r($rs); $sqlup = "update news set hits=hits+1 where `id`='".$_GET['id']."'";
mysql_query($sqlup); }
?>
<div class="g-wrap m-infor-details">
<h1 class="mid-title"><?php echo $rs['title']; ?></h1>
<p class="mid-con">
<?php echo $rs['contents']; ?>
</p>
<div class="mid-bot">
<span class="mid-b-l">时间:
<?php echo $rs['dates']; ?>
</span>
<span class="mid-b-r">点击量:
<?php echo $rs['hits']; ?>
</span>
</div>
</div>
conn.php
<?php
//@不把错误暴露出来
@mysql_connect("localhost:3306","root","123456") or die("mysql链接失败");
@mysql_select_db("test") or die("db链接失败"); //mysql_set_charset("gbk");//php5.2.3以上
mysql_query("set names 'gbk'");
?>
main.css
*{
margin:;
padding:;
}
li{
list-style-type: none;
}
body{
background-color: #1B9102;
font-size: 14px;
}
/*....................................index.html...........*/
.g-wrap{
margin: 50px auto 0;
width: 500px;
min-height: 300px;
box-shadow: 0 0 10px #fff;
}
.m-top{
background-color: #d2d2d2;
overflow: hidden;
}
.mt-link{
float: left;
}
.mt-search{
float: right;
font-size:;
}
[type=submit]{
cursor: pointer;
}
.mi-list{
color: #adadad;
padding-top: 20px;
border-bottom: 1px dashed #fff;
}
.ml-top{
color: #333;
}
.ml-cen{
margin-top: 10px;
font-size: 12px;
}
.ml-bot{
height: 50px;
line-height: 50px;
margin-top: 10px;
}
.mb-l{
float: left;
color: pink;
}
.mb-r{
float: right;
cursor: pointer;
}
/*......................................add.html...........*/
.m-form{
padding: 20px;
box-sizing: border-box;
}
.m-form li{
margin-bottom: 20px;
}
.m-form label{
color: #fff;
vertical-align: top;
}
/*......................................view.html...........*/
.m-infor-details{
padding: 20px 20px 50px;
box-sizing: border-box;
position: relative
}
.mid-title{
color: #fff;
text-align: center;
}
.mid-con{
color: #a9a9a9;
font-size: 14px;
margin-top: 20px;
text-indent: 30px;
}
.mid-bot{
position: absolute;
right: 20px;
bottom:;
left: 20px;
height: 50px;
line-height: 50px;
color: #fff;
}
.mid-b-l{
float: left;
}
.mid-b-r{
float: right;
}
PHP留言小练习的更多相关文章
- 微信小程序 「柒留言」 — 实现微信公众号留言功能(限时免费入驻,建议收藏)
「柒留言」小程序留言助手使用指南(接近原生界面) 前言 从去年 3 月以后新公众号就没得留言功能了,新申请的微信公众号没有留言功能,没有留言就无法跟读者进行互动,写出去的文章得不到反馈,着实感觉有蛮难 ...
- 微信小程序新服务消息推送 —— 订阅消息
微信团队前不久公测了「订阅消息」,原有的小程序模板消息接口将于 2020 年 1 月 10 日下线,届时将无法发送模板消息.「订阅消息」将完全替代「模板消息」,这两天得空测试了一波. 1.下发权限机制 ...
- node实战小例子
第一章 2020-2-6 留言小本子 思路(由于本章没有数据库,客户提交的数据放在全局变量,接收请求用的是bodyParser, padyParser使用方法 app.use(bodyParser.u ...
- FPGA入门实例一:LFSR
一:任务: 要求使用Verilog语言在Xilinx Virtex-6开发板上实现线性反馈移位寄存器(LFSR)的硬件逻辑设计. 二:前期准备: 基本上完成一个简单的设计需要用到以下几个软件 逻辑:U ...
- Kali环境使用Metasploit生成木马入侵安卓手机
Metasploit是一款开源的安全漏洞检测工具,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,提供真正的安全风险情报.这些功能包括智能开发,代码审计, ...
- nodejs+express+jade+mongodb给我baby做个小相册(2)-留言板
上一篇简单的实现了下照片的展现跟浏览功能,这一篇我将给这个程序添加一个留言的功能.那么留言的话肯定要涉及到数据持久了,其实对于这个小功能的话,用个xml就可以,不过为了看起来更加高大上,我决定使用mo ...
- 微信小程序实现简易留言板
微信小程序现在很火,于是也就玩玩,做了一个简易的留言板,让大家看看,你们会说no picture you say a j8 a,好吧先上图. 样子就是的,功能一目了然,下面我们就贴实现的代码,首先是H ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 小博客| 登录 | 注册 | 留言 | 提Bug 小博客
浏览(1502) 赞(29) 一直以来都想开发一个自己的网站,总想做一个网站然后让千千万万的人去访问,去使用,然后收到热烈的好评, 再然后某某著名机构有意投资我的网站(其实收购也是没有问题的), ...
随机推荐
- RF ---library
RF内置库: http://robotframework.org/robotframework/ SSHLibrary: ---WEB自动化测试 http://robotframework.org ...
- ARM和STM32的区别及ARM公司架构的发展
ARM和STM32的区别及ARM公司架构的发展 转:https://www.cnblogs.com/kwdeblog/p/5260348.html ARM是英国的芯片设计公司,其最成功的莫过于32位嵌 ...
- NGINX下如何自定义404页面
什么是404页面 如果碰巧网站出了问题,或者用户试图访问一个并不存在的页面时,此时服务器会返回代码为404的错误信息,此时对应页面就是404页面.404页面的默认内容和具体的服务器有关.如果后台用的是 ...
- android开发系列之视频断点续传
今天在这篇博客里面,我想说说自己在这几天遇到的一个棘手的问题,就是视频断点续传的问题.其实这在我们开发中是一个很常见的应用场景,比如视频.音频.pdf等相关的文档.如果之前没有接触过的话,你也许会被这 ...
- SkipList跳跃表(Java实现)
取自网络https://github.com/spratt/SkipList AbstractSortedSet.java package skiplist_m; /***************** ...
- PowerBuilder -- 未公开函数
原文:http://blog.csdn.net/happymagic/article/details/51077322 @.已知一个DW中的某列的列名(在字符串变量中),以获得这个列对象的DWO 方法 ...
- HTML5,不仅仅是看上去非常美(第二弹:打造最美3D机房)
前言 近期项目开发任务告一段落,刚好有时间整理这大半年的一些成果.使用html5时间还不久,对js的认识还不够深入.没办法,曾经一直搞java,对js的一些语言特性和概念一时还转换只是来. 上一篇第一 ...
- Linux系统初始化流程
POST-->BIOS(Boot Sequence)-->MBR(bootloader)-->Kernel(initrd)-->/sbin/init(/etc/inittab) ...
- 多线程快速解压FastZipArchive介绍
本文转载至 http://blog.csdn.net/xunyn/article/details/12975937 多线程解压iosfast 在iOS项目中用到解压缩,用的是ZipArchive ...
- Why Use C++/CLI?
来源:http://www.asawicki.info/Download/Productions/Publications/CPP_CLI_tutorial.pdf Why Use C++/CLI? ...