smarty编写新闻管理系统(一)
2011-11-22 21:59
260 查看
今天老师总结了smarty知识点,开始带我们做新闻管理系统,课上加上课下做的如下:
登陆界面:login.php
<?php
include("./conn.php");
include("./init.inc.php");
//开启session
session_start();
//M+C
if(isset($_POST['submit'])){
$user=$_POST['username'];
$pass=$_POST['password'];
$_SESSION['username']=$user;
$sql="select * from user where username='{$user}' and passwd='{$pass}'";
echo $sql;
$result=$mysqli->query($sql);
$nums=$result->num_rows;
if($nums==0){
echo "username is not exit";
}else{
header("Location:index.php");
}
}
$tpl->display("login.html");
?>
模板:login.html
<html>
<head>
<title>这个模板文件</title>
<style type="text/css">
body{
margin-top:40px;
}
.style{
font-size:38px;
font-weight:bold;
}
</style>
</head>
<body>
<p class="style">这个模板文件</p>
<form name="myform" method="post">
<table border="2" width="290">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" /></td>
</tr>
</table>
<input type="submit" name="submit" value="提交" />
</form>
</body>
</html>
新闻显示页面:
index.php
<?php
include("./conn.php");
include("./init.inc.php");
session_start();
$name=$_SESSION['username'];
$mysqli->query("set names utf8");
$sql="select * from news";
$result=$mysqli->query($sql);
while($row=$result->fetch_assoc()){
$data[]=$row;
}
$tpl->assign("name",$name);
$tpl->assign("data",$data);
$tpl->display("index.html");
?>
模板文件:index.html
<html>
<head>
<title>这是模板文件</title>
<style>
body{
margin-top:50px;
}
#name{
font-size:18px;
color:red;
}
#table{
margin-left:30px;
}
</style>
</head>
<body>
欢迎<span id="name"> <{ $name }> </span>登陆 !! <a href="login.php">安全退出</a>
<p>这是模板文件</p>
<hr />
<br><br>
<table width="800" height="200" border="0" id="table">
<tr>
<td>系统管理</td>
<td>
<form>
<table border="0" width="500">
<tr>
<td width="120">标题</td>
<td width="120" align="center">日期</td>
<td width="120" align="center">选择</td>
</tr>
<{*循环显示数据库数据*}>
<{section name=data loop=$data}>
<tr>
<td><{$data[data].title}></td>
<td><{$data[data].date}></td>
<td align="center"><input type="checkbox" name="checkbox[]"></td>
</tr>
<{/section}>
</table>
</td>
</tr>
<tr>
<td><a href="edit.php">添加新闻</a></td>
<td>
<input type="submit" value="删除" />
</form>
</td>
</tr>
</table>
</body>
</html>
添加新闻页面:
edit.php
<?php
session_start();
include("./init.inc.php");
include("./conn.php");
include('./FCKeditor/fckeditor.php');
$name=$_SESSION['username'];
$mysqli->query("set names utf8");
if(empty($_POST['sub'])){
$title=$_POST['title'];
$content=$_POST['content'];
$sql="insert into news(author,title,content,datetime) values('{$name}','{$title}','{$content}',now())";
echo $sql;
$mysqli->query($sql);
}
$tpl->display("edit.html");
?>
模板文件:
edit.html
<html>
<head>
<title>新建新闻</title>
</head>
<body>
<br><br>
<p>新闻管理登陆</p>
<hr>
<table width="771" height="501" border="0">
<tr>
<td height="62"><div align="center">系统管理</div></td>
<td width="666" rowspan="2">
<form name="form1" method="post" action="edit.php">
<p>标题
<input name="title" type="text" id="title" value="">
</p>
<p>内容:</p>
<p>
<div>
<input type="hidden" id="content" name="content" value="" style="display:none" />
<input type="hidden" id="content___Config" value="AutoDetectLanguage=true&DefaultLanguage=en" style="display:none" />
<iframe id="content___Frame" src="./FCKeditor/editor/fckeditor.html?InstanceName=content&Toolbar=Default"
width="100%" height="320" frameborder="0" scrolling="no"></iframe>
</div>
</p>
<p>
<input type="submit" name="sub" value="提交">
<!--<input type="hidden" name='action' value=addnews>
<input name="id" type="hidden" value="">-->
</p>
</form>
</td>
</tr>
<tr>
<td width="95" height="433"><div align="center">添加新闻</div></td>
</tr>
</table>
</body>
</html>
明天继续!!
登陆界面:login.php
<?php
include("./conn.php");
include("./init.inc.php");
//开启session
session_start();
//M+C
if(isset($_POST['submit'])){
$user=$_POST['username'];
$pass=$_POST['password'];
$_SESSION['username']=$user;
$sql="select * from user where username='{$user}' and passwd='{$pass}'";
echo $sql;
$result=$mysqli->query($sql);
$nums=$result->num_rows;
if($nums==0){
echo "username is not exit";
}else{
header("Location:index.php");
}
}
$tpl->display("login.html");
?>
模板:login.html
<html>
<head>
<title>这个模板文件</title>
<style type="text/css">
body{
margin-top:40px;
}
.style{
font-size:38px;
font-weight:bold;
}
</style>
</head>
<body>
<p class="style">这个模板文件</p>
<form name="myform" method="post">
<table border="2" width="290">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" /></td>
</tr>
</table>
<input type="submit" name="submit" value="提交" />
</form>
</body>
</html>
新闻显示页面:
index.php
<?php
include("./conn.php");
include("./init.inc.php");
session_start();
$name=$_SESSION['username'];
$mysqli->query("set names utf8");
$sql="select * from news";
$result=$mysqli->query($sql);
while($row=$result->fetch_assoc()){
$data[]=$row;
}
$tpl->assign("name",$name);
$tpl->assign("data",$data);
$tpl->display("index.html");
?>
模板文件:index.html
<html>
<head>
<title>这是模板文件</title>
<style>
body{
margin-top:50px;
}
#name{
font-size:18px;
color:red;
}
#table{
margin-left:30px;
}
</style>
</head>
<body>
欢迎<span id="name"> <{ $name }> </span>登陆 !! <a href="login.php">安全退出</a>
<p>这是模板文件</p>
<hr />
<br><br>
<table width="800" height="200" border="0" id="table">
<tr>
<td>系统管理</td>
<td>
<form>
<table border="0" width="500">
<tr>
<td width="120">标题</td>
<td width="120" align="center">日期</td>
<td width="120" align="center">选择</td>
</tr>
<{*循环显示数据库数据*}>
<{section name=data loop=$data}>
<tr>
<td><{$data[data].title}></td>
<td><{$data[data].date}></td>
<td align="center"><input type="checkbox" name="checkbox[]"></td>
</tr>
<{/section}>
</table>
</td>
</tr>
<tr>
<td><a href="edit.php">添加新闻</a></td>
<td>
<input type="submit" value="删除" />
</form>
</td>
</tr>
</table>
</body>
</html>
添加新闻页面:
edit.php
<?php
session_start();
include("./init.inc.php");
include("./conn.php");
include('./FCKeditor/fckeditor.php');
$name=$_SESSION['username'];
$mysqli->query("set names utf8");
if(empty($_POST['sub'])){
$title=$_POST['title'];
$content=$_POST['content'];
$sql="insert into news(author,title,content,datetime) values('{$name}','{$title}','{$content}',now())";
echo $sql;
$mysqli->query($sql);
}
$tpl->display("edit.html");
?>
模板文件:
edit.html
<html>
<head>
<title>新建新闻</title>
</head>
<body>
<br><br>
<p>新闻管理登陆</p>
<hr>
<table width="771" height="501" border="0">
<tr>
<td height="62"><div align="center">系统管理</div></td>
<td width="666" rowspan="2">
<form name="form1" method="post" action="edit.php">
<p>标题
<input name="title" type="text" id="title" value="">
</p>
<p>内容:</p>
<p>
<div>
<input type="hidden" id="content" name="content" value="" style="display:none" />
<input type="hidden" id="content___Config" value="AutoDetectLanguage=true&DefaultLanguage=en" style="display:none" />
<iframe id="content___Frame" src="./FCKeditor/editor/fckeditor.html?InstanceName=content&Toolbar=Default"
width="100%" height="320" frameborder="0" scrolling="no"></iframe>
</div>
</p>
<p>
<input type="submit" name="sub" value="提交">
<!--<input type="hidden" name='action' value=addnews>
<input name="id" type="hidden" value="">-->
</p>
</form>
</td>
</tr>
<tr>
<td width="95" height="433"><div align="center">添加新闻</div></td>
</tr>
</table>
</body>
</html>
明天继续!!
相关文章推荐
- 利用Smarty编写新闻管理后台系统
- Smarty编写新闻管理系统(二)
- Smarty编写新闻管理系统(三)
- PHP基础示例:用PHP+Mysql编写简易新闻管理系统[转]
- 缓存总结 SMARTY新闻管理系统分析
- 今天利用Smarty写了一个新闻管理后台系统
- PHP基础示例:用PHP+Mysql编写简易新闻管理系统
- php面向对象操作mysql数据库,简单的新闻管理系统的编写
- smarty新闻管理系统
- smarty实现简单新闻管理系统
- 用c++编写简单的图书管理系统怎么弄
- 《C语言编写 学生成绩管理系统》
- 智库ams新闻文章内容管理系统utf8 v1.1
- 编写新闻发布系统 显示新闻条目时间问题
- 一个用C语言编写的小型文件管理系统 基于VC6.0
- 《C语言编写 学生成绩管理系统》
- Python 学习--编写“学生管理系统”
- 【linux下用C语言编写带图形界面的成绩管理系统附带源代码】
- 《C语言编写 学生成绩管理系统》
- 安卓SQLite数据库操作,半小时开发新闻管理系统,纯干货