您的位置:首页 > 其它

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>

明天继续!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: