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> <!- ...
随机推荐
- ASP.NET MVC遍历ModelState的错误信息
在ASP.NET MVC中,ModelState中包含了验证失败的错误信息,具体被存储在ModelState.Values[i].Errors[j].ErrorMessage属性中.当然,通过打断点, ...
- Delphi XE 6,Rad Studio XE 6 官方下载(附破解)
官方光盘镜像下载: http://altd.embarcadero.com/download/radstudio/xe6/delphicbuilder_xe6_win.iso RAD Studio ...
- ios测试宏指令出错:“Expected identefier”
写了一个简单的测试宏指令,然后在下面代码中报错,不知道怎么修复?谢谢 #define test(condition) do{\ if (condition) {\ //// <-----Expe ...
- HTML5之SVG
1.背景 SVG是Scalable Vector Graphics的缩写,意为可缩放矢量图形.1998年,万维网联盟成立了一个工作组,研发一种通过 XML来表现矢量图形的技术——SVG!由于SVG也是 ...
- Windows下安装WebLogic
WebLogic安装结束 以下是进入MyEclipse启动配置WebLogic
- Quartz 2.3.0 升级感受
Quartz 2.3.0 发布,Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中.它提供了巨大的灵 活性而不牺牲简单性.你能够用它来为执行一个作业而创建简 ...
- 《“胡”说IC——菜鸟工程师完美进阶》
<“胡”说IC——菜鸟工程师完美进阶> 基本信息 作者: 胡运旺 出版社:电子工业出版社 ISBN:9787121229107 上架时间:2014-5-15 出版日期:2014 年5月 开 ...
- IPython介绍
本文编写时,IPython最新的版本为6.3和5.4. 介绍 IPython 是 Fernando 在 2001 开始开发的一个交互式的Python解释执行环境.众所周知,Python提供了一个交互执 ...
- FrameLayout框架布局的的动态配置
导包省略…… acticity.java public class MainActivity extends Activity { @Override protected void onCreate( ...
- [转]使用mysql profiles 来查看sql 语句执行计划
From : http://blog.csdn.net/radkitty/article/details/4632289 要使用该功能,mysql的版本必须在5.0.37版本以上.否则只能使用expl ...