自己发明的一种表单自动判断POST地址的方法 ++ 节省文件数
时间:2009-09-15
来源:互联网
其实我们可以这样写。。总共只有1个页面
[php]
<?php
if (isset($GET['action'])) {
exit;
}
require_once('../include/common.inc.php');
switch ($_GET['action'])
{
case 'new_article':
$posturl = 'article_edit.php?action=insert';
break;
case 'insert';
$title = $_POST['title'];
$cid = $_POST['cid'];
$preview = $_POST['preview'];
$content = $_POST['content'];
$tags = $_POST['tags'];
$date = date("Y-m-d H:i:s");
$top = intval($_POST['top']);
$etop = intval($_POST['editortop']);
$ftop = intval($_POST['flashtop']);
$top1 = intval($_POST['top1']);
$sql = "insert into articles(title,cid,preview,content,tags,date,top,etop,ftop,top1,hits) values('$title','$cid','$preview','$content','$tags','$date','$top','$etop','$ftop','$top1',1)";
if(mysql_query($sql)){
$aid = mysql_insert_id();
//置顶
if ($top) {
$sql = "insert into toparticles(aid,title,type) values('$aid','$title',1)";
mysql_query($sql);
}
//编辑推荐
if ($etop) {
$sql = "insert into toparticles(aid,title,type) values('$aid','$title',2)";
mysql_query($sql);
}
//flash幻灯推荐
if ($ftop) {
;
}
turnto("article_list.php","添加文章成功!");
}else {
jsjump("back","添加文章失败!");
}
exit;
case 'edit_article':
empty($_GET['id'])?exit():$id = $_GET['id'];
$posturl = 'article_edit.php?action=update';
$sql = "select * from articles where id=$id";
$topsql = "select * from toparticles where aid=$id";
$rs = mysql_query($sql);
$article = mysql_fetch_array($rs);
break;
case 'update':
$id = $_POST['id'];
$title = $_POST['title'];
$cid = $_POST['cid'];
$preview = $_POST['preview'];
$content = $_POST['content'];
$tags = $_POST['tags'];
$top = intval($_POST['top']);
$etop = intval($_POST['editortop']);
$ftop = intval($_POST['flashtop']);
$top1 = intval($_POST['top1']);
$sql = "update articles set title='$title',
cid='$cid',
preview='$preview',
content='$content',
tags='$tags',
top='$top',
etop='$etop',
ftop='$ftop',
top1='$top1'
where id='$id';
";
if(mysql_query($sql)){
$aid = $id;
//置顶
if ($top) {
$sql = "select * from toparticles where aid=$aid and type=1";
if (!mysql_fetch_array(mysql_query($sql))) {
$sql = "insert into toparticles(aid,title,type) values('$aid','$title',1)";
mysql_query($sql);
}
}else {
$sql = "select * from toparticles where aid=$aid";
if (mysql_query($sql)) {
$sql = "delete from toparticles where aid=$aid and type=1";
mysql_query($sql);
}
}
//编辑推荐
if ($etop) {
$sql = "select id from toparticles where aid=$aid and type=2";
if (!mysql_fetch_array(mysql_query($sql))) {
$sql = "insert into toparticles(aid,title,type) values('$aid','$title',2)";
mysql_query($sql);
}
}else {
$sql = "select * from toparticles where aid=$aid";
if (mysql_query($sql)) {
$sql = "delete from toparticles where aid=$aid and type=2";
mysql_query($sql);
}
}
if ($top) {
;
}
turnto("article_list.php","修改文章成功!");
}else {
jsjump("back","修改文章失败!");
}
exit;
case 'delete':
empty($_GET['id'])?exit():$id = $_GET['id'];
$sql = "delete from articles where id=$id";
if(mysql_query($sql)){
mysql_query("delete from toparticles where aid=$id");
turnto("article_list.php","删除文章成功!");
}else {
turnto("article_list.php","删除文章失败!");
}
exit;
default:
exit('Error');
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body bgcolor="#DDEEFF">
<center><table width="95%" height="auto" cellpadding="0" cellspacing="1" bgcolor="#ADD2DA">
<tr>
<td height="190" valign="top"><br/>
<form enctype="multipart/form-data" id="form1" action="<?= $posturl?>" method="POST">
<input type="hidden" name="id" id="id" value="<?= $article['id']?>"/>
<table width="98%" align="center" cellpadding="0" cellspacing="1" style="word-break:break-all;">
<tr align="center">
<td height="15" align="center"bgcolor="#F1F1F1">标题</td>
<td height="20" align="left" bgcolor="#FFFFFF"><input type="text" name="title" value="<?=$article['title']?>" style="width:500px;"/></td>
</tr>
<tr align="center">
<td width="80" height="14" align="center"bgcolor="#F1F1F1">文章分类</td>
<td height="20" align="left" bgcolor="#FFFFFF"><span class="STYLE1">
<select name="cid" id="cid">
<?php foreach ($categories as $category) {?>
<option value="<?= $category['id']?>"><?= $category['name']?></option>
<?php ;}?>
</select>
</span></td>
</tr>
<tr>
<td height="183" align="center" bgcolor="#F1F1F1"><span class="menuCss1">文章预览</span></td>
<td height="234" align="left" bgcolor="#FFFFFF">
<?php
include_once("./editor/fck/fckeditor.php");
$oFCKeditor = new FCKeditor('preview') ;
$oFCKeditor->BasePath = "./editor/fck/";
$oFCKeditor->Value = $article['preview'] ;
$oFCKeditor->Height="100%";
$oFCKeditor->Width="100%";
$oFCKeditor->Create() ;
?>
</td>
</tr>
<tr>
<td height="183" align="center" bgcolor="#F1F1F1"><span class="menuCss1">文章正文</span></td>
<td height="400" align="left" bgcolor="#FFFFFF">
<?php
$oFCKeditor = new FCKeditor('content') ;
$oFCKeditor->BasePath = "./editor/fck/";
$oFCKeditor->Value = $article['content'] ;
$oFCKeditor->Height="100%";
$oFCKeditor->Width="100%";
$oFCKeditor->Create() ;
?>
</td>
</tr>
<tr align="center">
<td height="15" align="center"bgcolor="#F1F1F1">关键词</td>
<td height="20" align="left" bgcolor="#FFFFFF"><input type="text" name="tags" value="<?=$article['tags']?>" style="width:400px;"/></td>
</tr>
<tr>
<td height="20" align="center" bgcolor="#F1F1F1">推荐</td>
<td height="20" align="left" bgcolor="#FFFFFF">
<input type="checkbox" id="top" name="top" value="1" <?=$article['top']?'checked':''?>>置顶推荐</input>
<input type="checkbox" id="editortop" name="editortop" value="1"<?=$article['etop']?'checked':''?> >编辑推荐</input>
<input type="checkbox" id="flashtop" name="flashtop" value="1" <?=$article['ftop']?'checked':''?>>幻灯推荐</input>
<input type="checkbox" id="top1" name="top1" value="1" <?=$article['top1']?'checked':''?>>头条推荐</input>
</td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#F1F1F1">附件</td>
<td height="30" align="left" bgcolor="#FFFFFF"><input type="file" name="file" id="file"/></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#F1F1F1">配图</td>
<td height="30" align="left" bgcolor="#FFFFFF"><input type="file" name="showpic" id="showpic"/></td>
</tr>
<tr>
<td height="40" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="submit"/></td>
</tr>
</table></form></td>
</tr>
<tr height="10" align="center"></tr>
</table></center>
</body>
</html>
[/php]
作者: oik550 发布时间: 2009-09-15
exit;
}
啥意思
作者: yafeikf 发布时间: 2009-09-15
作者: c10h15n 发布时间: 2009-09-15
作者: wade2006 发布时间: 2009-09-15
作者: ZendFramework 发布时间: 2009-09-15
那只能够说明你都没有看过开源程序!
作者: 齐迹 发布时间: 2009-09-15
作者: flyeast 发布时间: 2009-09-15
支持楼主!
作者: timeshi 发布时间: 2009-09-15
作者: yilong 发布时间: 2009-09-15
不过鼓励你的这种行为。多思考,才有进步。
但是。。。。重复造轮子是吃力不讨好的
作者: 某个人 发布时间: 2009-09-15
作者: sinopf 发布时间: 2009-09-15
了解了。。。框架都是单入口。这个确实有用
版主闭帖吧
作者: oik550 发布时间: 2009-09-16
当然,楼主的创新精神值得鼓励。
作者: lvbibo 发布时间: 2009-09-16
作者: myBe 发布时间: 2009-09-16
作者: jxncpbs 发布时间: 2009-09-16
楼主的头像很强大~~~
作者: linzhoulxyz 发布时间: 2009-09-16

这个是基础,人人都知道的啊
不过我倒是有真的发明,呵呵
暂时不告诉你
作者: lqfox66 发布时间: 2010-09-14

作者: lqfox66 发布时间: 2010-09-14
index.php
-
- <?php
- class artitle extends app
- {
- function indexAction()
- {
- $this->tpl->dispaly('index.html');
- }
- function addAction()
- {
- //添加文章的代码
-
- }
- }
- app::run(__FILE__);
- ?>
模板文件 index.html
-
- <form action='?action=add'>
- ......表单项目
- <input type='submit'/>
- </form>
作者: lqfox66 发布时间: 2010-09-14
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28