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> <!- ...
随机推荐
- delphi 启动停止windows服务 转
http://blog.csdn.net/haiou327/article/details/6106233 不用cmd用delphi如何实现启动停止windows服务建议参考一下Delphi的Sckt ...
- delphi 服务程序
http://www.delphifans.com/InfoView/Article_662.html 用Delphi创建服务程序 Windows 2000/XP和2003等支持一种叫做"服 ...
- C#获取文件夹及文件的大小与占用空间的方法
本文详细介绍了利用C#实现根据路径,计算这个路径所占用的磁盘空间的方法 . 网上有很多资料都是获取文件夹/文件的大小的.对于占用空间的很少有完整的代码.这里介绍实现这一功能的完整代码,供大家参考一下. ...
- 在arcgis使用python脚本进行字段计算时是如何解决中文问题的
来自:https://www.jb51.net/article/73561.htm 一.引言 在arcgis打开一个图层的属性表,可以对属性表的某个字段进行计算,但是在平常一般都是使用arcgis提供 ...
- Java获取URL链接的文件类型
问题发生: Java从网络批量读取图片并保存至本网站服务器后再插入文章中 今天转入一篇文章 http://news.qq.com/a/20170605/045860.htm 发现图片未能成功上传 查看 ...
- PL/SQL报错:Initialization error Oracle client not properly installed
安装PL/SQL8.4后,连接数据库 提示错误Initialization error Oracle client not properly installed 解决方案: 1.下载instancec ...
- 黑吃黑第一季/全集Banshee迅雷下载
第一季 Banshee Season 1 (2013)看点:“Banshee”在爱尔兰盖尔语中被称为“bean sidhe”,意思是“拥有超能力的女人”.不过在鲍尔的新剧中,Banshee并不是指超自 ...
- ios成长之每日一遍(day 1)
Hello world开始. 这里不讨论如何创建项目导入项目.由于趁上班时间打酱油所以也不谈细节, 只谈具体项目的实现与关键流程的解析, 只供本人实际程况使用.不喜请移驾. 首先来谈谈 AppDele ...
- Verilog 加法器和减法器(2)
类似半加器和全加器,也有半减器和全减器. 半减器只考虑当前两位二进制数相减,输出为差以及是否向高位借位,而全减器还要考虑当前位的低位是否曾有借位.它们的真值表如下: 对半减器,diff = x ^y, ...
- JS Replace() 高级用法(转)
在很多项目中,我们经常需要使用JS,在页面前面对前台的某些元素做做修改,js 的replace()方法就必不可少. 经常使用"ABCABCabc".replace("A& ...