php学习实例3
新闻发布管理系统
路由器action.php
<!DOCTYPE html>
<html>
<head>
<title> </title>
<meta charset="utf-8">
</head>
<body>
<?php
require("dbconfig.php");
$link = @mysql_connect(HOST, USER, PASS) or die("db error");
mysql_select_db(DBNAME, $link); echo "action";
switch($_GET["action"]) {
case "add" :
$title = $_POST["title"];
$keywords = $_POST["keywords"];
$author = $_POST["author"];
$content = $_POST["content"];
$addtime = time(); $sql = "insert into news values(null, '{$title}', '{$keywords}', '{$author}', {$addtime}, '{$content}')";
//echo $sql;
$link.mysql_query($sql);
$id = mysql_insert_id($link);
if($id>) {
echo "<a>成功</a>";
}else{
echo "<a>失败</a>";
}
echo "<a href='./index.php'>返回主页</a>";
break;
case "del" :
$id = $_GET["id"];
$sql = "delete from news where id={$id}";
mysql_query($sql);
header("Location:index.php");
break;
case "update" :
$id = $_POST["id"];
$title = $_POST["title"];
$keywords = $_POST["keywords"];
$author = $_POST["author"];
$content = $_POST["content"];
$addtime = time(); $sql = "update news set title='{$title}',keywords='{$keywords}',author='{$author}',content='{$content}',addtime={$addtime} where id = ${id}"; //echo $sql; $result = mysql_query($sql);
header("Location:index.php");
break;
} mysql_close($link);
?>
</body>
</html>
统一导航栏menu.php
<ul>
<li>
<a href="index.php">浏览新闻</a>
</li>
<li>
<a href="add.php">发布新闻</a>
</li>
</ul>
首页index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<?php
include("menu.php");
?>
<table border="">
<thead>
<tr>
<th>id</th>
<th>标题</th>
<th>关键字</th>
<th>作者</th>
<th>时间</th>
<th>内容</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php
require("dbconfig.php");
$link = @mysql_connect(HOST, USER, PASS) or die ("mysql error");
mysql_select_db("newsdb", $link); $sql = "select * from news order by addtime desc";
$result = mysql_query($sql, $link);
while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['title']}</td>";
echo "<td>{$row['keywords']}</td>";
echo "<td>{$row['author']}</td>";
echo "<td>".date("Y-m-d",$row['addtime'])."</td>";
echo "<td>{$row['content']}</td>";
echo "<td><a href='./action.php?action=del&id={$row['id']}'>删除</a> <a href='./edit.php?id={$row['id']}'>修改</a>
</td>";
echo "</tr>";
};
mysql_free_result($result);
mysql_close($link);
?>
<tr>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
数据库管理 dbconfig.php
<?php
define("HOST","localhost");
define("USER","root");
define("PASS","");
define("DBNAME","newsdb");
?>
数据添加add.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<?php
include("menu.php");
?>
<form action="action.php?action=add" method="post">
<table border="">
<tbody>
<tr>
<td>标题</td>
<td>
<input type="text" name="title">
</td>
</tr>
<tr>
<td>关键字</td>
<td>
<input type="text" name="keywords">
</td>
</tr>
<tr>
<td>作者</td>
<td>
<input type="text" name="author">
</td>
</tr>
<tr>
<td>内容</td>
<td>
<textarea name="content" rows="" ></textarea>
</td>
</tr>
<tr>
<td colspan="">
<input type="submit" value="add">
<input type="reset" value="reset">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
数据编辑edit.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<?php
include("menu.php");
require("dbconfig.php");
$link = @mysql_connect(HOST, USER, PASS) or die ("mysql error");
mysql_select_db("newsdb", $link);
$id = $_GET['id'];
$sql = "select * from news where id='{$id}'";
$result = mysql_query($sql, $link);
if($result && mysql_num_rows($result)>) {
$news = mysql_fetch_assoc($result);
}else{
echo "no data";
};
?>
<form action="action.php?action=update" method="post">
<table border="">
<input type="hidden" name="id" value="<?php echo $news['id'] ?>">
<tbody>
<tr>
<td>标题</td>
<td>
<input type="text" name="title" value="<?php echo $news['title'] ?>">
</td>
</tr>
<tr>
<td>关键字</td>
<td>
<input type="text" name="keywords" value="<?php echo $news['keywords'] ?>">
</td>
</tr>
<tr>
<td>作者</td>
<td>
<input type="text" name="author" value="<?php echo $news['author'] ?>">
</td>
</tr>
<tr>
<td>内容</td>
<td>
<textarea name="content" rows="" ><?php echo $news['content'] ?></textarea>
</td>
</tr>
<tr>
<td colspan="">
<input type="submit" value="add">
<input type="reset" value="reset">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
文件上传下载系统
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<form action="flist.php" method="post" enctype="multipart/form-data">
<input type="file" name="pic" />
<input type="submit" value="upload">
</form>
<?php
echo "<pre>";
var_dump($_FILES);
$typelist = array("image/jpeg","image/jpg","image/png");
@$up = $_FILES["pic"];
if(!empty($up)){
switch($up["error"]) {
case :
$info = "";
break;
}
if( !in_array($up["type"], $typelist)) {
echo "error type";
return ;
}
if( is_uploaded_file($up["tmp_name"]) ) {
$upname = iconv('utf-8','gb2312',$up['name']);
if(move_uploaded_file($up["tmp_name"], "./uploads/".$upname)) {
echo "<br>success<br>";
}else{
echo "<br>error<br>";
}
}
echo "</pre>"; }?>
<?php
$dir = opendir("uploads");
$i = ;
while($f = readdir($dir)) {
if($f == "." || $f=="..") {
continue;
}
$i++;
$name=iconv("gb2312","utf-8",$f);
echo "{$i}";
echo "<img src='uploads/{$name}' />";
echo "<br>";
}
?>
</body>
</html>
基于本地文本文件的留言管理系统
首页添加留言:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<center>
<form action="doAdd.php" method="POST">
标题:<input type="text" name="title">
<br>
作者:<input type="text" name="author">
<br><br>
内容:<textarea name="content">
</textarea>
<br>
<input type="submit" value="提交">
</form>
</center>
</body>
</html>
添加留言的业务逻辑:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$title = $_POST["title"];
$author = $_POST["author"];
$content = $_POST["content"];
$ip = $_SERVER["REMOTE_ADDR"];
$addtime = time(); $ly = "{$title}##{$author}##{$content}##{$ip}##{$addtime}@@";
$ly = $ly.file_get_contents("ly.txt");
$flag = file_put_contents("ly.txt", $ly);
if(!$flag) {
echo "error";
return;
}else{
header('Location: '.'./list.php');
} ?>
</body>
</html>
查看留言列表:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<ul>
<?php
$content = file_get_contents("ly.txt");
$content = rtrim($content, "@@");
$arr = explode("@@", $content); foreach($arr as $k=>$list) {
echo "<li>";
$con = explode("##", $list);
echo "标题:{$con[0]}, 作者:{$con[1]}, 内容:{$con[2]} ,ip:{$con[3]}, 时间:".date('Y-m-d',$con[])."<a href='del.php?id={$k}'>del</a>";
echo "</li>";
}
?>
</ul>
</body>
</html>
删除留言:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php
$id = $_GET["id"];
$con = file_get_contents("ly.txt");
$con = rtrim($con, "@@");
$list = explode("@@", $con);
unset( $list[$id] ); $result = implode("@@", $list);
file_put_contents("ly.txt", $result);
header("Location: ./list.php");
?>
</body>
</html>
<?php $arr = array(,,,);
foreach( $arr as $i){
echo $i."\n";
}
作者: NONO
出处:http://www.cnblogs.com/diligenceday/
企业网站:http://www.idrwl.com/
开源博客:http://www.github.com/sqqihao
QQ:287101329
微信:18101055830
厦门点燃未来网络科技有限公司, 是厦门最好的微信应用, 小程序, 微信网站, 公众号开发公司
php学习实例3的更多相关文章
- Ant学习实例
ant 目录(?)[+] Ant学习实例 安装Ant 基础元素 project元素 target元素 property元素 完整示例 Ant学习实例 1.安装Ant 先从http://ant. ...
- zTree学习实例
今天做完一个zTree的实例,供有需要的学习! 效果图如下:
- (转)jQuery插件编写学习+实例——无限滚动
原文地址:http://www.cnblogs.com/nuller/p/3411627.html 最近自己在搞一个网站,需要用到无限滚动分页,想想工作两年有余了,竟然都没有写过插件,实在惭愧,于是简 ...
- jQuery插件编写学习+实例——无限滚动
最近自己在搞一个网站,需要用到无限滚动分页,想想工作两年有余了,竟然都没有写过插件,实在惭愧,于是简单学习了下jQuery的插件编写,然后分享出来. 先说下基础知识,基本上分为两种,一种是对象级别的插 ...
- WCF通信简单学习实例
最近在学习WCF通信,自己简单做个实例分享一下,环境是VS2015,使用的项目都是WPF的项目,其实大家用Winform或者Web项目也可以,都可以用的. 一.服务器端 1.创建WCF服务 服务名为W ...
- React入门最好的学习实例-TodoList
前言 React 的核心思想是:封装组件,各个组件维护自己的状态和 UI,当状态变更,自动重新渲染整个组件. 最近前端界闹的沸沸扬扬的技术当属react了,加上项目需要等等原因,自己也决定花些时间来好 ...
- Spring Security3学习实例
Spring Security是什么? Spring Security,这是一种基于Spring AOP和Servlet过滤器的安全框架.它提供全面的安全性解决方案,同时在Web请求级和方法调用级处理 ...
- gulp入门学习实例
好久都没有更新博客了,每天繁忙的工作,下班之后都不想开设备了.前段时间有幸学习了一下gulp这款构建工具,现在和大家分享一下. 为什么使用Gulp Gulp基于Node.js的前端构建工具,通过Gul ...
- Matlab学习------------带有右键菜单的GUI学习实例
实例步骤: 须要设置UIContextMenu,否则点击右键不显示. 右键点击第一个菜单之后:(在菜单中加入对应的回调函数) function r1_Callback(hObject, eventda ...
- SVG矢量图学习实例
从W3school上学习了一下SVG矢量图形,感觉和HTML相比还是有一些新的元素和属性的,一时间不能全部记住,特此留下笔记,供遗忘时作为参考 <!DOCTYPE html> <!- ...
随机推荐
- Android自己定义控件系列二:自己定义开关button(一)
这一次我们将会实现一个完整纯粹的自己定义控件,而不是像之前的组合控件一样.拿系统的控件来实现.计划分为三部分:自己定义控件的基本部分,自己定义控件的触摸事件的处理和自己定义控件的自己定义属性: 以下就 ...
- Delphi 19种反调试检测法
//使用IsDebuggerPresent这个API来检测是否被调试function FD_IsDebuggerPresent(): Boolean;beginif IsDebuggerPresent ...
- INDY10的IDHttpServer应答客户端
INDY10的IDHttpServer应答客户端 首先贴源码: procedure TIdHTTPResponseInfo.WriteContent; begin if not HeaderHasBe ...
- 【linux】在linux上生成SSH-key 简单原理介绍+生成步骤
1.首先什么是SSH Secure Shell (SSH) 是一个允许两台电脑之间通过安全的连接进行数据交换的网络协议.通过加密保证了数据的保密性和完整性.SSH采用公钥加密技术来验证远程主机,以及( ...
- 一文犀利看懂中美贸易战 z
如今的中国面对着前所未有的经济全球化的大环境.面对着如何成为创新性国家的重任. 钛媒体注:美国东部时间 7 月 6 日凌晨0:01 分,美国正式开始对 340 亿美元的中国产品加征 25% 的关税,这 ...
- WordPress主题开发:get_term_by和get_term_link
学习目的: 某一个分类的名称.别名.和id都可以到后台自己去找,但这样找比较麻烦还容易看错,wordpress提供了下面两个函数get_term_by和get_term_link,只要提供别名.名称或 ...
- 用SDWebImage加载FLAnimatedImage
用SDWebImage加载FLAnimatedImage 效果 源码 https://github.com/YouXianMing/Animations // // GifPictureControl ...
- mysql 查询时间戳(TIMESTAMP)转成常用可读时间格式
from_unixtime()是MySQL里的时间函数 date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串 后面的 '%Y%m%d' 主要是将返回值 ...
- Android之greenDao,一个orm的使用
转自:http://blog.csdn.net/krislight/article/details/9391455 greenDaoMaster的学习研究 分类: 心得笔记 2013-07-20 16 ...
- [转]mysql 一个表两列的值交换
FROM : http://bbs.csdn.net/topics/380025779 mysql> select * from test1 +------+-------+-------+ | ...